jquery - Adding/Removing Active Class Onclick -
i'm trying add "active" class h3 jquery once heading has been clicked , have removed when h3 clicked. i've tried many examples here on stackoverflow cannot class add.
here example of code:
<div id="qa-faq0" class="qa-faq cf"> <h3 class="qa-faq-title"><a class="qa-faq-anchor" href="#">frequently asked question #1</a></h3> <div class="qa-faq-answer" style="display: none;"><p>frequently asked question #1 content goes here</p> </div> </div>
thanks in advance!
try http://jsfiddle.net/aamir/6aruq/1/
$(function(){ var $h3s = $('h3').click(function(){ $h3s.removeclass('active'); $(this).addclass('active'); }); });
or http://jsfiddle.net/aamir/6aruq/2/
$(function(){ $('h3').click(function(){ $('h3.active').removeclass('active'); $(this).addclass('active'); }); });
Comments
Post a Comment