Reputation: 33
am stuck with a issue.juz started studying jquery recently..i do hav a issue
i have a segment like this in ma html code..what i need is to select the li tag that comes just before the 'a' tag that i clicked.it would b helpful if someone helped me with this. i need to add a class named open in the li class just before the 'a' tag that is being clicked.. how can i do this using jquery..
<ul>
<li class=''>
<a class ='value1'></a>
<div>some contents</div>
</li>
<li class=''>
<a class ='value 2'></a>
<div>some contents</div>
</li>
</ul>
Upvotes: 2
Views: 97
Reputation: 70718
Try:
$("a").click(function() {
$(this).parent().addClass("open");
});
I have added some content to your a
tag for this to work in JSFiddle.
Upvotes: 1