$("form input")
| Select the input elements in all form elements |
$("#main > *") | Select all child elements whose id value is main |
$("label input") | Select the next input element node of all label elements. After testing, the selector returns all input label elements that are directly followed by an input label. |
##$(" #prev ~ div")
Sibling selector, this selector returns all div tags belonging to the same parent element of the tag element with id prev |
|
Note: Chain operations can only be performed if this method returns a JQuery object.
3. jquery filter selector
The filter selector mainly filters out the required DOM elements through specific filtering rules. The filtering rules are the same as the pseudo ones in CSS. The syntax of class selectors is the same, that is, the selectors start with a colon (:) (for more information about css pseudo-class selectors, please refer to css Learning Manual). According to different filtering rules, filter selectors can be divided into basic filtering, content filtering, visibility filtering, attribute filtering, sub-element filtering and form filtering.
There are six types of selectors for object attribute filtering selectors. Let's take a brief look at the six jquery filter selectors
(1) jquery basic filter selector
Filter selectors are based on certain types of filtering rules. The matching of elements starts with (:) when written; the simple filter selector is the most widely used type of filter selector.
$("tr:first"): Select the first of all tr elements
$("tr:last"): Select the last of all tr elements
$("input:not(:checked) span"): Filter out all input elements of: checked selector
$("tr:even"): Select the 0th of all tr elements , 2, 4... elements (note: because the selected elements are arrays, the sequence numbers start from 0)
$("tr:odd"): Select all The 1st, 3rd, 5th... element of the tr element
$("td:eq(2)"): Select the td element with serial number 2 among all td elements
$("td:gt(4)"): Select all td elements with sequence numbers greater than 4 in td elements
$("td:ll(4)"): Select td elements All td elements with serial numbers less than 4
$(":header"): Match header elements such as h1, h2, h3. This is specially used to obtain headers such as h1 and h2. Element
$("div:animated"): Matches all elements that are performing animation effects
(2) jquery content filter selector
The filtering rules of the content filtering selector are mainly reflected in the sub-elements and text content it contains.
$("div:contains('John')"): Select all elements containing John text in the div
$("td:empty"): Select all elements that are empty ( Array of td elements (not including text nodes)
$("div:has(p)"): Select all div elements containing p tags
$("td:parent" ): Select all element arrays with td as the parent node
(3) jquery visibility filter selector
The visibility filter selector is based on the visible and Invisible state to select the corresponding element.
$("div:hidden"): Select all hidden div elements
$("div:visible"): Select all visible div elements
(4) jquery attribute filter selector
The filtering rule of the attribute filter selector is to obtain the corresponding element through the attribute of the element.
$("div[id]"): Select all div elements containing the id attribute
$("input[name='newsletter']"): Select all div elements whose name attribute is equal to 'newsletter' input elements
$("input[name!='newsletter']"): Select all input elements whose name attribute is not equal to 'newsletter'
$("input [name^='news']"): Select all input elements whose name attribute starts with 'news'
$("input[name$='news']"): Select all name attributes Input elements ending with 'news'
$("input[name*='man']"): Select all input elements whose name attribute contains 'news'
(5) jquery child element filter selector
$("ul li:nth-child(2)"),$("ul li:nth-child(odd)"),$( "ul li:nth-child(3n 1)"): Matches the Nth child or odd-even element under its parent element. This selector is somewhat similar to eq() in Basic Filters mentioned before, but different The difference is that the former starts from 0 and the latter starts from 1.
$("div span:first-child"): Returns an array of the first child nodes of all div elements
$("div span:last-child" ): Returns an array of the last node of all div elements
$("div button:only-child"): Returns an array of all child nodes that have only one child node in all divs
(6) jquery form object attribute filter selector
This selector mainly filters the selected form elements.
$(":enabled"): Select all operable form elements
$(":disabled"): Select all inoperable form elements
$(":checked"): Select all checked form elements
$("select option:selected"): Select all selected elements in the child elements of select
$("input[@ name =S_03_22]").parent().prev().text(): Select the text value of the previous td of the input text box named "S_03_22"
$ ("input[@ name ^='S_']").not("[@ name $='_R']"): The name starts with "S_" and does not end with "_R"
$("input[@ name =radio_01][@checked]").val();: The selected value of a radio named radio_01
$(" A B"): Find all child nodes under the A element, including indirect child nodes
$("A>B"): Find the direct child nodes under the A element
$(" A B"): Find the sibling nodes behind the A element, including indirect child nodes
$("A~B"): Find the sibling nodes behind the A element, excluding indirect child nodes
4. jquery form selector
Using the form selector, we can easily obtain a certain element or type of element of the form.
Note: Note: The method to select the hidden value in the input is the usage in the above example, but if you use ":hidden" directly, it will match all invisible elements in the page, including those with a width or height of 0 .
$(":input"): Select all form input elements, including input, textarea, select and button
$(":text"): Select all text input elements
$(":password"): Select all password input elements
$(":radio"): Select all radio input elements
$(":checkbox "): Select all checkbox input elements
$(":submit"): Select all submit input elements
$(":image"): Select all image input elements
$(":reset"): Select all reset input elements
$(":button"): Select all button input elements
$(":file "): Select all file input elements
$(":hidden"): Select all input elements of type hidden or hidden fields of the form
The above is the entire content of this article For more information about the jquery selector, you can refer to jquery Online Manual on the php Chinese website for further information! ! !