javascript - .addClass to only the bullet being clicked on in unordered list -


i have short unordered list 2 bullets.

i added javascript, when bullet clicked on, adds class it.

the problem is, adds class existing li's, not 1 clicked on.

here jsfiddle: http://jsfiddle.net/4sa8t/

javascript:

$("#items li a").click(function(){  $("#items li").addclass("newclass");  }); 

html:

<div id="content">     <ul id="items">     <li><a href="#">hello</a></li>     <li><a href="#">bye</a></li>         </ul> </div> 

$("#items li a").click(function(){     $("#items li").addclass("newclass"); }); 

should be

$("#items li a").click(function(){     $(this).parent().addclass("newclass"); }); 

$(this).parent() refer specific li element, , $('#items li') refers all lis under #items


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -