li.target").css("border", "3px double r...">

How to select an item inside "this" in jQuery?

I know if I can select an element this way:

$("ul.topnav > li.target").css("border", "3px double red"); 

but how can I do something like:

 $(this > li.target).css("border", "3px double red"); 
+84
jquery
01 Feb '11 at 10:16
source share
2 answers
 $( this ).find( 'li.target' ).css("border", "3px double red"); 

or

 $( this ).children( 'li.target' ).css("border", "3px double red"); 

Use children for immediate descendants, or find for deeper elements.

+171
Feb 01 '11 at 10:17
source share

I use this to get the parent, similarly for the child

 $( this ).children( 'li.target' ).css("border", "3px double red"); 

Luck

+8
May 30 '13 at 9:49
source share



All Articles