I want to make a menu, and change the class when clicking.
When i click on the "li" with no class="active"
, i want jquery to add a class on the empty <li>
and remove it from the othes "li".
<li class="active"><a href="javascript:;" onclick="$.data.load(1);">data</a></li>
<li><a href="javascript:;" onclick="$.data.load(2);">data 2</a></li>
can somebody help me ? :)
jQuery add active class to the menu: Adding a class to List tag . i.e li element on button click. This article explains how to add a class to Li or any HTML tag using jQuery.
var interest = $('ul#credit'). find('li. active'). attr('interest');
I think you mean this:
$('li > a').click(function() {
$('li').removeClass();
$(this).parent().addClass('active');
});
// When we click on the LI
$("li").click(function(){
// If this isn't already active
if (!$(this).hasClass("active")) {
// Remove the class from anything that is active
$("li.active").removeClass("active");
// And make this active
$(this).addClass("active");
}
});
$('li').click(function()
{
$('li', $(this).parent()).removeClass('active');
$(this).addClass('active');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With