Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Apr 2005
    Posts
    97
    Thanks
    0
    Thanked 0 Times in 0 Posts

    changing style with Javascript (resolved)

    I'm trying to have an onClick event change the css properties of another element on my page.

    In my CSS i have declared
    Code:
      div#extra {
        visibility: hidden;
      }
    Code:
        function showAdvanced()
        {
          document.getElementById("extra").style.visibility="visible";
        }
    is my function, I'm not sure if its right, I don't much experience with DOM, especially getElementById();

    I have a sneaking suspicion the function isn't even being called though.

    I call to it here:
    Code:
    <a href="" id="showAdvanced" onclick="showAdvanced();">Advanced &raquo;</a>
    The problem is, when I click it, nothing happens.
    Can you see the problem, or do you need more code?

    Thanks.
    Last edited by pjleonhardt; 09-22-2005 at 07:11 AM.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Code:
    <a href="" id="showAdvanced" onclick="showAdvanced();return false">Advanced &raquo;</a>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Apr 2005
    Posts
    97
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That didn't fix it, unfortunately. Though I figure it IS something as simple as that.

    [:timelapse=30seconds:]

    Okay, I figured it out. (Though, I prob. needed the return false as well.)

    I had <script type="javascript">
    instead of language="javascript"

    to much CSS (type="text/css")

    Thanks for you help, Paul

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    The only real problem I saw was the return false which is good when you don't want the href to be activated. Because you had type="javascript" okay yes thats a problem. It should be type="text/javascript". language="javascript" is deprecated and shouldn't be used. The type declaration however should be used as it is required in order to validate.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    New Coder
    Join Date
    Apr 2005
    Posts
    97
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Excellent. Thank you.


  •  

    Posting Permissions

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