SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Evangelist
    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;
    //test.htm
    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>
    but nothing happens, either i use 'none', or '' or even 'hide'
    what am i doing wrong?

    TiA

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    should be:
    Code:
    paragrafo.style.display = 'none';
    display not displays

  3. #3
    SitePoint Evangelist
    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...

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    must be a typo, does your script work now though?

  5. #5
    SitePoint Evangelist
    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

  6. #6
    SitePoint Zealot nicc9's Avatar
    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();
    instead of
    Code:
    window.onload = oculta;
    ?

    just a thought...

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by nicc9 View Post
    shoudn't it be
    Code:
    window.onload = oculta();
    instead of
    Code:
    window.onload = oculta;
    ?

    just a thought...
    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="^$">

  8. #8
    SitePoint Zealot
    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>

  9. #9
    SitePoint Zealot
    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

  10. #10
    SitePoint Evangelist
    Join Date
    Apr 2003
    Location
    lisboa
    Posts
    423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by funkdaddy View Post
    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>
    cant use hide, but none or '' instead, and so works fine
    tx


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •