Javascript-triggered CSS "display" change

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • musicmaster890
    New Member
    • Apr 2008
    • 11

    Javascript-triggered CSS "display" change

    Okay, I cannot figure this out. I have an external javascript file to declare variables and functions in my <head> element of my HTML. I've done this before and have made it work. And, likewise, studied my past suceeding brew and litterally copy and pasted the function but it still refuses to cooperate with me. What am I trying to do? I'll let the code do the talking:

    Code:
    function dispChange(eid){if(document.getElementById(eid).style.display=="none"){document.getElementById(eid).style.display="inline";}else{document.getElementById(eid).style.display="none";}}
    that's my function. It makes 'eid's .style.display either "inline" or "none" appropriately, so I would have something like...

    [HTML]<a href="javascrip t:dispChange('s Nav')" class="dispTogg ">...</a>[/HTML]

    and there would be <span> element with the id 'sNav'. I'm completely stumped. hopefully thats enough info- this is my first question on here, so... yeah. that's that. Thanks for the help!
  • musicmaster890
    New Member
    • Apr 2008
    • 11

    #2
    Originally posted by musicmaster890
    Okay, I cannot figure this out. I have an external javascript file to declare variables and functions in my <head> element of my HTML. I've done this before and have made it work. And, likewise, studied my past suceeding brew and litterally copy and pasted the function but it still refuses to cooperate with me. What am I trying to do? I'll let the code do the talking:

    Code:
    function dispChange(eid){if(document.getElementById(eid).style.display=="none"){document.getElementById(eid).style.display="inline";}else{document.getElementById(eid).style.display="none";}}
    that's my function. It makes 'eid's .style.display either "inline" or "none" appropriately, so I would have something like...

    [HTML]<a href="javascrip t:dispChange('s Nav')" class="dispTogg ">...</a>[/HTML]

    and there would be <span> element with the id 'sNav'. I'm completely stumped. hopefully thats enough info- this is my first question on here, so... yeah. that's that. Thanks for the help!
    Nevermind- I figured it out. When I called my JScript file I used "href" instead of "src".

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Glad to hear that you managed to solve it (and within the hour too!)

      Just a note on links. Put the function call in an onclick and either make the href point to a real URL or just #:
      [HTML]<a href="#" onclick="dispCh ange('sNav'); return false;" class="dispTogg ">...</a>[/HTML]It doesn't change it much, but it's better to allow for JavaScript being disabled.

      Comment

      Working...