Get the code of a specific stator element in jquery _ jquery

Source: Internet
Author: User
This article mainly introduces how to obtain the code of a specific sub-element in jquery. If you need it, you can refer to some JQUERY applications that have been made earlier, the selector does not have high requirements, like "$ ('. class ') "," $ (' # id') "," $ ('# id>. class ') "," $ (this) "," $ (this ). parent () "," $ (this ). children () "can solve these simple statements.

The problem is that I want to select a span from a li In ul, because li is $ ('ul> li ') to facilitate programming '). although the problem can still be solved using the previous method, eq (I) always feels that the Code is a bit bloated and inefficient. Since JQUERY is hailed as the most efficient code in all JS frameworks, it is impossible to solve this problem with a large amount of code!

After turning back to JQUERY's API, I found a statement that is very suitable for this scenario. I have never paid attention to it. That is: $ (selector 1). find (selector 2 ). Although I have read the "find" section before, it has been ignored because it is not used.

Here is how to use find ().
API: searches for all elements that match the specified expression. This function is a good way to find the child element of the element being processed.

Usage: $ (selector 1). find (selector 2 );

Take the focus chart on the home page of the little drama Inn, look for the span in the DD under the DL with the class ". focusphoto" and fade it out for example:

The Code is as follows:


$ ('. Focusphoto> dl> dd). eq (I). find ("span"). fadeOut ('low ');

Let's talk about the small drama's understanding of find ().

My application can be replaced by children (), but this does not mean that the usage of find () and children () is the same. If so, find () is meaningless. When the query depth is a Level 1, the two are the same, but the difference is that find () is a subquery selector, which can go deep into the sublevel for query selection; children (): A child selector. It can only select the next level of elements.

Of course, the above are just a few comments from the people in the drama. If there are errors or imperfections, please correct me. Thank you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.