Reputation: 658
hi i am working on a project i wanna catch of a parent but i could not do it thank you for your advice
this is what is in html part
<li> <a class="siralaMain" catid="7" href="#"> <span>Sahil</span> </a>
<ul style="display: block;">
<li> <a class="siralaSec active" catid="300" href="#"> </li>
</ul>
</li>
$(this)
references <a class="siralaSec active" catid="300" href="#">
here
when i made
$(this).parent().parent().parent().addClass("active");
it addClass to li so it becomes like this
<li class="active"> <a class="siralaMain" catid="7" href="#"> <span>Sahil</span> </a>
<ul style="display: block;">
<li> <a class="siralaSec active" catid="300" href="#"> </li>
</ul>
</li>
but i need to addClass
to a
like this
<a class="siralaMain active">
thanks for any advice
Upvotes: 1
Views: 99
Reputation: 44740
How about this -
$(this).parents("li:eq(1)").find("a:first").addClass("active");
http://jsfiddle.net/mohammadAdil/4zgM2/1/
Upvotes: 0
Reputation:
$(this).closest('.siralaMain').addClass('active');
seem like you need to use:
$(this).closest('ul').prev().addClass('active');
Upvotes: 2
Reputation: 2469
try this
$(this).closest('ul').prev('.siralaMain').addClass('active');
Upvotes: 0
Reputation: 104775
This works:
$(this).parent().parent().parent().find("a").addClass("active");
Fiddle: http://jsfiddle.net/Afgnz/
Upvotes: 0
Reputation: 196002
Use
$(this).closest('li:has(.siralaMain)')
.find('.siralaMain')
.addClass('active');
Upvotes: 0
Reputation: 324650
Ugly parent
chain is ugly.
$(this).parent("li").parent("li").find("a").eq(0).addClass("active");
Upvotes: 0