I'm just curious... how am I supposed to use 'this' within a jQuery function?
For example, if I have some code like this...
headEl.find("form.blog-search input").focus(function() {
$(this).next("span").animate({opacity:1}, 200);
})
It works fine, however when linting I get the warning of "Use of 'this' in closure".
Is this something I should just ignore, or is there something I can do to not only solve the warning, but improve my code?
Update:
Based on Kevin B's comment below, I changed up the code to
headEl.find("form.blog-search input").on('focus', function(event) {
$(event.target).next("span").animate({opacity:1}, 200);
})
Which works as expected... now I'm just curious, what are the downsides to this method and when should it be used in favor of this
or vice-versa?