Monday, 15 July 2013

javascript - Change class onClick using jquery -


I have a navigation that shows an active status using class = "active". When a link is clicked, I have to add an "Active" class to click, and all other links will have to remove the "Active" class.

Here's my code:

  & lt; Div id = "references" & gt; & Lt; Div id = "refer 1" & gt; & Lt; A href = "javascript:;" OnClick = "changeClass ();" Class = "active" & gt; & Lt; / A & gt; & Lt; / Div & gt; & Lt; Div id = "referLink2" & gt; & Lt; A href = "javascript:;" OnClick = "changeClass ();" Class = "" & gt; & Lt; / A & gt; & Lt; / Div & gt; & Lt; Div id = "refer33" & gt; & Lt; A href = "javascript:;" OnClick = "changeClass ();" Class = "" & gt; & Lt; / A & gt; & Lt; / Div & gt; & Lt; / Div & gt;   

Any help would be appreciated! Try it out:

  function changeclass () {$ ('$')   

And you should also force the function in Javakrat like this:

  $ ('#NotNav A'). On ('click', changeclass);   

In this way, as reported in Travis J., $ (this) will reference the correct object.



No comments:

Post a Comment