Hello friends,

I got a problem while trying to hide and display the content within the <div> tag. Can anyone tell me how to do it. I tried with the following code its not working. i am using IE only and i want to work in IE only. Actually while loading the page the content should be in hide state.

function doInit() {
    	alert( "DoInit 1" );
    	element = document.getElementById('<divName>');
	element.style.display = 'none';
}

and

funtion doInit() {
document.getElementById(<divName>).style.visibility = 'hidden';
}

JavaScript != Java

I have already asked the admins to move the thread.

Hello,
Firstly, it is really annoying that people keep posting JavaScript questions in the Java forum. They are so different.

Secondly, you got two things wrong:
1. Your <divName> is relavant for us. The function getElementById(), gets and element by it's ID, unlike the function getElementByName()!
2. In the second function, <divName> is not wrapped.

So, just change change your div:
From: <div name="<divName>"></div>
To: <div id="<divID>"></div>

The name doesn't matter, just pick one (you can make it id="Shaffer" for all your browser cares, just make only one. If more, your code will crash).

Anyhow,
this is how your page should look (add more stuff freely)...

<html>
<head>
  <script type="text/javascript">
funtion doInit() {
  document.getElementById('<divID>').style.visibility = 'hidden';
}
  </script>
</head>
<body onload="doInit()">
  <div id="<divID>"></div>
</body>

Notice the body onload="" since you wanted this to happen on page load.

Oh, and I see absolutely no reason for your first function to work!


Shaffer.

Thank you,

And friends sorry for posting this javascript Q in java. It wont happen hereafter..

Hello,
it's ok, don't worry about it.
Did it work?


Shaffer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.