Click to See Complete Forum and Search --> : NS7 DHTML hide and shown object


allier
03-26-2003, 05:09 AM
I am working on DHTML and the way to hide and shown object.

Webreference.com give a very simple example (see above) which doesn't work with NS7.

Searching thoughout the Internet, I found that depending of the browser one should should use "hide" or "hidden, but I have try those solutions with no success.

I also known that I can achieve what I want with the "getElementById" method but what I like to understand is why NS7 doesn't understand obj.style.visibility

nb1 : NS7 java consol error message is "Erreur : mypar is not defined"

nb2 : I also searched also on cross-browser DHTML web site, but there examples did not work with NS7 !.
(eg : http://www.dansteinman.com/dynduo/examples/showhide1.html)


---------------------------------------------------
Example working with IE5.5 but not with NS7.01

<HTML>
<HEAD>
<TITLE>Removing Objects</TITLE>
<!-- simplified from www.webreference.com/js/tips/000903.html OK with IE5.5 KO with NS7 -->
<SCRIPT LANGUAGE = "JavaScript">
<!--
function disappear(obj) {
obj.style.visibility = "hidden";
}
// -->
</SCRIPT>

</HEAD>
<BODY>
<SPAN onClick="disappear(mypar)">
Click here to remove the paragraph below:
</SPAN>
<p>
<SPAN ID="mypar">
Blah Blah Blah
</SPAN>
<p>
</body>
</HTML>

gil davis
03-26-2003, 06:01 AM
Internet Explorer allows all kinds of loose syntax, and vague references to objects. Netscape, on the other hand, strictly adheres to the W3C DOM recommendations. Netscape cannot see an object called "mypar" from the context of the span onclick: it simply does not exist in that context.

The easiest method for getting a pointer to "mypar" is to use document.getElementById(). There are other ways of traversing the document tree, but this one is not position dependent since it relies on the assignment of a unique id.

allier
03-26-2003, 07:50 AM
Thank's for the rapid answer.

Sometime, I like "loose" syntax but this time I can't.

BTW, I have found a good example of what I was looking for :

http://getelementbyid.com/tutorials/getelementbyid_method/index.shtml