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
a: This selector matches all links (< a >) elements
#specialID: This selector matches an element with ID Specialid
. Spcialclass: This selector matches elements that have CSS class Specialclass
- 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 | Selector
Description |
: 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