javascript - How to change the Class using jquery -
my jquery code:
$('a#cusine1').on('click', function(){ $('div#product-list').html("loading..........").show(); $(".ccid").addclass("0"); document.getelementbyid("ccid1").classname="active2"; }); $('a#cusine2').on('click', function(){ $('div#product-list').html("loading..........").show(); $(".ccid").addclass("0"); document.getelementbyid("ccid2").classname="active2"; }); $('a#cusine3').on('click', function(){ $('div#product-list').html("loading..........").show(); $(".ccid").addclass(""); document.getelementbyid("ccid3").classname="active2"; }); my html code
<li id="ccid1" class="ccid"> <a href="#" id="cusine1"><i class="fa fa-ticket"></i>3 star hotel</a> </li> <li id="ccid2" class="ccid"> <a href="#" id="cusine2"><i class="fa fa-ticket"></i>3 star hotel</a> </li> <li id="ccid3" class="ccid"> <a href="#" id= "cusine3"><i class="fa fa-ticket"></i>5 star hotel</a> </li> output needed:
i need, when li id "ccid1" clicked, class "active2" should added. other li should have "ccid" class.
the number of li may change based on php.
problem found
in first time, when click li id "ccid1", class "active2" added. then, if li id "ccid2" clicked class "active2" added, li id "ccid1" class not set "0".
as i've said in comment, don't use classnames starting / - number.
this need:
$('.ccid a').on('click', function(){ // targets links $('div#product-list').html("loading..........").show(); $(".active2").removeclass("active2"); // remove existent active classes $(this).parent(".ccid").addclass("active2"); // set active class });
Comments
Post a Comment