Extend jquery $ (this)

How to simply increase the selector from $ (this) to, say, his children? Or something else. I mean, how to contcatenate them correctly with $ (this)?

how

$("li.nav").each(function() { $(this AND children of this, or this AND it siblings).something(); }); 

Sorry, if this has already been answered, could not be found.

+6
source share
1 answer

You can use andSelf to do the following:

 $(this).children().andSelf().something(); 

You can also use .end to display the last filtering operation of the current chain. Therefore, if you want children and brothers and sisters, you can do this too:

 $(this) .children() // children of "this" .end() // now we're back to "this" .siblings() // siblings of "this" .andSelf() // and "this" itself .something(); 
+8
source

Source: https://habr.com/ru/post/911193/


All Articles