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 li
s under #items
Comments
Post a Comment