Reputation: 8487
<div class='pagename lock' style='float:left;width:200px;'>
<a href='javascript:void(0);' class='pages' title='Click to Go' rel="id" >
</div>
$(".pages a[rel=id]").parent().addClass("unlock")
The Unlock
class is not adding in parent div
, why?
Upvotes: 1
Views: 97
Reputation: 34117
Hiya demo http://jsfiddle.net/xYdBj/7/
Good read: http://api.jquery.com/parent/
html
<div class='pagename lock' style='float:left;width:200px;'>
<a href='javascript:void(0);' class='pages' title='Click to Go' rel="id" >
</div>
jquery code
$(".pages").parent().addClass("unlock");
alert("class added" + $(".pagename").attr("class"));
Upvotes: 0
Reputation: 145478
Well. First of all, a
tag should be closed.
<div class='pagename lock' style='float:left;width:200px;'>
<a href='javascript:void(0);' class='pages' title='Click to Go' rel="id">Click</a>
</div>
Then, based on your example we can see that a
tag has pages
class, so we need to rewrite the jQuery selector:
$("a[rel='id'].pages").parent().addClass("unlock")
Upvotes: 0
Reputation: 342775
Your first selector is incorrect. It looks for anchors within elements with class .pages
. Try:
$("a[rel='id'].pages").parent().addClass("unlock")
Upvotes: 3