Syed
Syed

Reputation: 2597

Add class to li on clicking ul tag using jquery

I'm clicking on ul tag and it has many li tags.. which ever li tag I click it should add a class "open" . Here is my code

$(document).on('click', '.navbar', function(e) { 

     $(this).find('li').addClass('open');
});

Html code

<ul class='navbar'>
     <li></li>
     <li></li>

</ul>

Upvotes: 0

Views: 144

Answers (1)

Shota Papiashvili
Shota Papiashvili

Reputation: 690

$('.navbar li').on('click', function(e){
    $(this).addClass('open');
});

Upvotes: 1

Related Questions