Home  >  Article  >  Web Front-end  >  Summary of jquery uncommon methods_jquery

Summary of jquery uncommon methods_jquery

WBOY
WBOYOriginal
2016-05-16 15:49:091065browse

1.jquery has a filtering API find.

The syntax is very simple, such as:

HTML code:

<p><span>Hello</span>, how are you&#63;</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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn