JQuery $ (this) syntax question

Is this a valid selector? If not, what is the right way?

$($(this)+' childElement')....
+1
source share
4 answers

Using

 $(this).find("childrenSelector")
+4
source

This may be what you are looking for:

$('childElement', $(this))

Basically it will search childElementin the context of the current element this.


See the documentation for the jQuery () function for more information . In particular, the following passage explains the second argument and how it is equivalent to using find:

DOM, . , $(). , , :

$('div.foo').click(function() {
  $('span', this).addClass('bar');
});

, clicked .

.find(), $('span', this) $(this).find('span').

+7
$(this).find('childrenSelector');
+4
source

Or...

$ (this) .children ('element.');

0
source

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


All Articles