Malik
Malik

Reputation: 347

Set div as background of other div

We have two divs. divOne contains information of image and divTwo contains information of table. Is it possible that we can set divOne as background image of divTwo using script?

divOne.innerHTML = <IMG src="http://sbc.com/xyz.jpg" />

divTwo.innerHTML = <TABLE id="content"> ....... </TABLE>

Upvotes: 0

Views: 920

Answers (2)

Scott Bonner
Scott Bonner

Reputation: 2980

divOne.style.backgroundImage="url(http://sbc.com/xyz.jpg);";

That should set divOne to that background image...


For the div Positioning give this a try...

divOne.style.position = "relative";
divOne.style.top = "0px";
divOne.style.left = "0px";
divOne.style.zIndex="1";

divTwo.style.position = "relative";
divTwo.style.top = "0px";
divTwo.style.left = "0px";
divTwo.style.zIndex="2";

Upvotes: 0

donohoe
donohoe

Reputation: 14123

Yes - depending on what you mean.

You can position one DIV over another using relative positions and z-index. If the top index is transparent (no background) then you should be able to see through to the one behind it.

Upvotes: 1

Related Questions