SitePoint Sponsor |
|
User Tag List
Results 1 to 10 of 10
-
Jan 24, 2007, 12:57 #1
- Join Date
- Apr 2003
- Location
- lisboa
- Posts
- 423
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
myElement.style.displays = 'hide';
i'm playing around with javascript and tried the following:
//a.js
HTML Code:function oculta() { var paragrafo = document.getElementById("a"); paragrafo.style.displays = 'hide'; } window.onload = oculta;
HTML Code:<html> <head> <title></title> <style type = "text/css"></style> <script type = "text/javascript" src = "a.js"></script> </head> <body> <p id = "a" >bla bla</p> </body> </html>
what am i doing wrong?
TiA
-
Jan 24, 2007, 13:01 #2
- Join Date
- Dec 2006
- Posts
- 182
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
should be:
Code:paragrafo.style.display = 'none';
-
Jan 24, 2007, 13:59 #3
- Join Date
- Apr 2003
- Location
- lisboa
- Posts
- 423
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
that's how i had it, but allways got a error msg saying invalid argument about display property;
so i went here:
http://developer.mozilla.org/en/docs/DOM:CSS
and changed it...
-
Jan 24, 2007, 14:27 #4
- Join Date
- Dec 2006
- Posts
- 182
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
must be a typo, does your script work now though?
-
Jan 24, 2007, 17:07 #5
- Join Date
- Apr 2003
- Location
- lisboa
- Posts
- 423
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
if i use display, i get that error msg, else, nothing happens
-
Jan 24, 2007, 17:50 #6
- Join Date
- Jan 2005
- Location
- New Orleans, LA
- Posts
- 181
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
shoudn't it be
Code:window.onload = oculta();
Code:window.onload = oculta;
just a thought...
-
Jan 24, 2007, 19:22 #7
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
Only if you want the oculta() function to run immediately and return the value that is to be run when the page finishes loading. If you want oculta to run after the page is loaded you need to leave off the () so that it assigns the function to the event handler and not the value returned from the function.
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
-
Jan 25, 2007, 07:43 #8
- Join Date
- Dec 2006
- Posts
- 182
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This code works fine for me, there must be something else in your script:
HTML Code:<html> <head> <title></title> <style type = "text/css"></style> <script type = "text/javascript"><!-- function oculta() { var paragrafo = document.getElementById("a"); paragrafo.style.display = "none"; } window.onload = oculta; //--> </script> </head> <body> <p id="a">bla bla</p> </body> </html>
-
Jan 25, 2007, 08:00 #9
- Join Date
- Jul 2006
- Posts
- 151
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you Felgall for explaining a problem I've had for ages. I was always getting those 'property not etc...' errors when I used window.onload, and now I understand why.
Dave
-
Jan 25, 2007, 15:21 #10
- Join Date
- Apr 2003
- Location
- lisboa
- Posts
- 423
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Bookmarks