The difference between filter, find, children, contents, contains in jquery

Source: Internet
Author: User

Although most of the front-end use jquery, but to jquery these selectors in use of similarities and differences, we should usually not care too much, or also smattering it!

Below is a brief summary of the following:

1.filter:

. Filter (selector)

. filter (function (index))

. Filter (Element)

. Filter (JQuery object)

And the find difference is that find is the operation of a subset of it, and the filter is an operation on its own collection element

2.find:

. Find (selector)

A. Find (jquery object) is one of the jquery objects used to match elements.

A. Find (Element) is a DOM element that is used to match elements.

The difference from children is that children only finds child elements, not descendant elements

3.children:

. Children ([selector])

The selector string that matches the element. Children (". Selected")

4.contents: The method returns all immediate child elements, including the text of the selected element and the comment node. A text node is the actual text that is displayed by the element. This method is similar to the children () method, but the difference is that it returns text and comment sections

and children the difference is that including text and comment nodes

5.contains:

JQuery (': Contains (text) ')

<div>john resig</div>

matches the text $ ("Div:contains (' John ')"). CSS ("text-decoration", "underline");//Find all DIV elements that contain "John"

$ ("ul Li" >.filter (": Contains (' Canon '),: Contains (' Nikon '),: Contains (' phone ')")). AddClass ("promoted");

Reprint: https://www.cnblogs.com/LiaoHao/p/3353335.html

The difference between filter, find, children, contents, contains in jquery

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.