jquery Combat: Create an element wrapper set, select the element that will be manipulated

Source: Internet
Author: User

What can you learn from reading?

1. Using the basic CSS Selector
2. Using sub-selectors, container selectors and feature selectors
3. Selection by location
4. Using a custom jquery selector

The first thing we have to do when using almost any jquery method is to select the page element that will be manipulated. Sometimes the collection of elements you want to select is easy to describe, such as "all linked elements on a page." Sometimes, a more complex description is needed, such as "even-numbered paragraphs with CSS class leftchild."

Fortunately, jquery provides a robust selector syntax that allows us to easily, elegantly and concisely specify a set of almost people and elements. Now let's learn about jquery's powerful selector feature.

Using the basic CSS Selector

    1. a: This selector matches all links (< a >) elements

    2. #specialID: This selector matches an element with ID Specialid

    3. . Spcialclass: This selector matches elements that have CSS class Specialclass

    4. p A. Specialclass: This selector matches the link element that has the CSS class Specialclass, declared within the < p > element

Using sub-selectors, container selectors, and feature selectors

Sub-selectors :

P>a: Select links that match only the direct child nodes of the < p > element
Ul>li>a: Select Direct child node of UL direct child node link

Container Selector :

Li:has (a): This selector matches all < li > elements that contain < a > element

feature selector :

A[HREF^=HTTP://]: This selector matches all links that start with http://
Input[type=text]: Match all < input > elements of type attribute value to text

Add: The basic CSS selector supported by jquery

selector description
*
E
E F match sign All elements called F, as descendant nodes of E
e>f match tag name F, all elements of immediate child node of e
e+f
e~f match all elements of the human and sibling node E before F (E and F can not be next to each other)
e:has (F) match label name E, at least one tag name is called All elements of the descendant node of F
e.c matches all elements with class name C E
e#f Match id attribute value to element e
E[a] matches all element E with attribute a (regardless of the value of attribute a)

Select by Location
Here I will list a few, need to view JQUERYAPI documents
a:first This format selector matches the first < a > element on a page
p:odd matches a paragraph element with an odd number of ordered numbers
P:even matches a paragraph element with an even number of ordered numbers
li:last-child Select the last child node of the parent element
: eq (n) nth matching element (n starting from 0)
: GT (n) the element after the nth matching element (excluding) (n starts from 0)
: The element preceding the n (n) nth matching element (excluding) (n starting from 0)

using the custom jquery selector (Here are a few examples)

Selector
SelectorDescription
: button Select any button
: checkbox Select only check box elements
: Contain (foo) Select only the elements that contain the text foo
: Hidden Select only hidden elements
: Text Select only Text field elements (Input[type=text])
: Not (Filter) Negation based on the specified filter

Summary:

jquery has a variety of selectors, you can choose according to their own habits, basically can specify any set of elements.

Author: by: Rodan Http://blog.csdn.net/sunyuan_software

jquery Combat: Create an element wrapper set, select the element that will be manipulated

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.