#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Posts
    33
    Rep Power
    14

    Question JS/CSS hide - OK is MSIE & OP, not in NS


    The following works in MSIE and Opera, but doesn't in Nescape. How can I adapt it so that it works with all of these browsers?

    <html>
    <head>
    <style type="text/css">
    <!--
    #test {display: block;}
    -->
    </style>

    <script language="JavaScript" type="text/JavaScript">
    <!--
    function doIt(theID)
    {
    var el = document.getElementById(theID);
    el.style.display="none";
    }
    //-->
    </script>
    </head>
    <body onResize="doIt('test');">
    <DIV id="test">Hide me!</DIV>
    </body>
    </html>
    Last edited by Jason Keeler; August 15th, 2003 at 06:11 PM.
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2003
    Posts
    804
    Rep Power
    101
    el.style.visibility = "hidden" should work in IE or NN.
  4. #3
  5. No Profile Picture
    The New User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    109
    Rep Power
    12
    That script does work in my NS 7.0, which version do you have? If it is NS 4.x, it might be the onResize handler, I do not think that is supported in NS 4.x

    --Neil
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2003
    Posts
    1,014
    Rep Power
    15
    Mozilla shows and hides the element without any problem (as expected). And I assume NS6+ does too.

    If you referred to Netscape 4: onresize is supported, but document.getElementById() is not and neither is the el.style.x syntax. I think this is as close as you can get:

    Code:
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function doIt(theID) {
    	if (document.getElementById) {
    		var el = document.getElementById(theID)
    		el.style.display = "none"
    	}
    	else if (document.layers) {
    		var el = document.layers[theID]
    		el.visibility = "hidden"
    	}
    }
    //-->
    </script>
    </head>
    <body onresize="doIt('test');">
    <div id="test" style="position: relative">Hide me!</div>
    Hope this helps,
    Jeroen
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Posts
    33
    Rep Power
    14
    Originally posted by knew youzr
    That script does work in my NS 7.0, which version do you have? If it is NS 4.x, it might be the onResize handler, I do not think that is supported in NS 4.x

    --Neil

    I've got NS 7.02. And I just double checked it - the script works OK on it.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Posts
    33
    Rep Power
    14
    Originally posted by jerom
    Mozilla shows and hides the element without any problem (as expected). And I assume NS6+ does too.

    If you referred to Netscape 4: onresize is supported, but document.getElementById() is not and neither is the el.style.x syntax. I think this is as close as you can get:

    Code:
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function doIt(theID) {
    	if (document.getElementById) {
    		var el = document.getElementById(theID)
    		el.style.display = "none"
    	}
    	else if (document.layers) {
    		var el = document.layers[theID]
    		el.visibility = "hidden"
    	}
    }
    //-->
    </script>
    </head>
    <body onresize="doIt('test');">
    <div id="test" style="position: relative">Hide me!</div>
    Hope this helps,
    Jeroen

    Thanks Jeroen, that works a treat - I haven't tried it in NS 4 yet.

IMN logo majestic logo threadwatch logo seochat tools logo