changing text onclick

Discussion in 'JavaScript' started by exinrex, Nov 4, 2007.

  1. #1
    hello guy's

    I'm very newbie with this. i just need some help. What i wanted is in the first click text "Open" it's will change to "Close" then if you click again the "Close" it will back into "Open".



    Thank's to you help.
     
    exinrex, Nov 4, 2007 IP
  2. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #2
    You can use this code:
    
    <html>
    <head>
    <script type="text/javascript">
    var open=1;
    function f_click()
    {
      elem = document.getElementById("myElem");
      if (open==1)
        { elem.innerHTML = "Close"; open=0; }
      else  
        { elem.innerHTML = "Open"; open=1; }
    }
    </script>
    </head>
    <body>
      <a id="myElem" href="javascript:f_click();">Open</a>
    </body>
    </html>
    
    Code (markup):
     
    ajsa52, Nov 4, 2007 IP
  3. exinrex

    exinrex Active Member

    Messages:
    413
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    81
    #3
    wow thank's for the quick response. I really use this.
     
    exinrex, Nov 4, 2007 IP