1.jquery has a filtering API find.
The syntax is very simple, such as:
HTML code:
<p><span>Hello</span>, how are you?</p>
jQuery code:
$("p").find("span")
Result:
[ <span>Hello</span> ]
But I was confused at first. This is not exactly the same as the $('p span') API. Why should I use this find?
I know I encountered an application scenario today.
The scene is like this. There is a div.skill. When the mouse passes over it, I need to add a new class to its sub-selector div.'skill-text',
Some students may ask why you don’t use event delegation:
$('.skill').on('mouseover',‘.skill-text',function(e){ $(this).addClass('skill-active'); });
Because I have processing code for '.skill' later, and there are many similar .skills, I cannot directly operate through $('.skill'), I must use this or e.target;
$('.skill').on('mouseover',function(e){ $(this).find('.skill-text').addClass('skill-active'); //.......其余代码 });
Very useful in this situation. Because you can't find the object directly using css selector.
Other than that, I really haven’t thought of any other good methods. How can I write it if the native js cannot be found? . . . 【Doubtful】
The above is the entire content of this article, I hope you all like it.