Home > Web Front-end > JS Tutorial > Summary of jquery uncommon methods_jquery

Summary of jquery uncommon methods_jquery

WBOY
Release: 2016-05-16 15:49:09
Original
1156 people have browsed it

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>
Copy after login

jQuery code:

$("p").find("span")

Copy after login

Result:

[ <span>Hello</span> ]

Copy after login

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');
});

Copy after login

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');

   //.......其余代码

});

Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template