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

Jquery

Jquery Problem Overview


I know can I 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");

Jquery Solutions


Solution 1 - Jquery

$( 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.

Solution 2 - Jquery

I use this to get the Parent, similarly for child

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

Good Luck

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondebView Question on Stackoverflow
Solution 1 - JqueryhookedonwinterView Answer on Stackoverflow
Solution 2 - JquerymchintaView Answer on Stackoverflow