JQuery Select context: this or $ (this)

When passing context to a selector, is it better to pass this or $(this) ? I tried the last one and it worked; document mentioned first.

 $('.link').on('click', function () { $('.element', this).addClass('something'); // or, $('.element, $(this)).addClass('something'); ? } 
+4
source share
1 answer

Using:

 $(this).find('.element').addClass('something'); 

$('.element', this) will turn into $(this).find('.element') internal.

+4
source

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


All Articles