View Full Version : i can't hide my div?

12-08-2006, 10:25 AM
hi friends h r u?
i have problem please if any body can solve
<div2>i want to hide this div</div>

document.getElementById("div1").innerHTML= "document.getElementById('div2').style.display = 'none'";

while displaying some text in div1 how can i hide div2

thanx in advance.

12-08-2006, 06:46 PM
If you want to differentiate between individual divs, you should do this:

<div id="1"></div>
<div id="2">I want to hide this div</div>

<div1> and <div2> are not valid HTML.

To remove div#2 (CSS term for the div with id '2') from the document flow, use this JavaScript code:

document.getElementById('2').style.display = 'none'; //(it can be restored with 'block' instead of 'none')

If you want to merely make it invisible, but retain a position in document flow (thereby displacing surrounding elements as if it were visible), use this:

document.getElementById('2').style.visibility = 'hidden';


12-08-2006, 07:49 PM
Unfortunately in the example above the IDs are invalid. IDs can't begin with a number or any special characters.