1
<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?

1
  • 1
    What do you think which elements are selected by .pages a[rel=id]? Have a look at the documentation: api.jquery.com/category/selectors Commented May 11, 2012 at 9:32

3 Answers 3

3

Your first selector is incorrect. It looks for anchors within elements with class .pages. Try:

$("a[rel='id'].pages").parent().addClass("unlock")
Sign up to request clarification or add additional context in comments.

Comments

0

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")

Comments

0

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"));​

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.