Filter Selector
The filter selector mainly filters out the required DOM elements through specific filtering rules. The selectors all start with ":"
According to different filtering rules, filter selectors can be divided into basic filtering, content filtering, visibility filtering, attribute filtering, sub-element filtering and form object attribute filtering selectors.
Basic Filter Selector
Basic filter selector example
Change the background color of the first div element to #bbffaa
Change the background color of the last div element to #bbffaa
Change the background color of all div elements whose class is not one to #bbffaa
Change the background color of the div element with an even index value to #bbffaa
Change the background color of div elements with odd index values to #bbffaa
Change the background color of div elements with index values greater than 3 to #bbffaa
Change the background color of the div element with index value equal to 3 to #bbffaa
Change the background color of div elements with index values less than 3 to #bbffaa
Change the background color of all title elements to #bbffaa
Change the background color of all elements currently being animated to #bbffaa
Content filter selector
The filtering rules of the content filtering selector are mainly reflected in the sub-elements and text content it contains
Content filtering selector example
Change the background color of the div element containing the text 'di' to #bbffaa
Change the background color of empty div elements that do not contain child elements (or text elements) to # bbffaa
Change the background color of the div element containing the class mini element to #bbffaa
Change the background color of the div element containing child elements (or text elements) to #bbffaa
Visibility filter selector
The visibility filter selector selects the corresponding elements based on their visible and invisible status
Visible selector: hidden not only includes elements whose style attribute display is none, but also includes elements such as text hidden fields () and visible:hidden
Visibility filter selector example
Change the background color of all visible div elements to #bbffaa
Select all invisible elements, use the show() method in jQuery to display them, and set their background color to # bbffaa
Select all hidden text fields and print their values
Attribute filter selector
The filtering rule of the attribute filter selector is to obtain the corresponding element through the attribute of the element
Attribute filter selector example
Select the following elements and change their background color to #bbffaa
A div element containing the attribute title.
A div element whose attribute title value is equal to "test".
Divide elements whose attribute title value is not equal to "test" (those without attribute title will also be selected).
A div element whose attribute title value starts with "te".
A div element whose attribute title value ends with "est".
A div element whose attribute title value contains "es".
Select the div element with the attribute id, and then select the div element with the attribute title value containing "es" in the results.
Child element filter selector
nth-child() selector is explained in detail as follows:
(1) :nth-child(even/odd): Can select elements whose index value under each parent element is an even (odd) number
(2):nth-child(2): Can select the element with index value 2 under each parent element
(3):nth-child(3n): Can select elements whose index value under each parent element is a multiple of 3
(3):nth-child(3n 1): Can select the element whose index value is 3n 1 under each parent element
Example of child element filter selector
Select the following elements and change their background color to #bbffaa
The second child element under the parent element of each div with class one.
The first child element under the parent element of each div with class one
The last child element under the parent element of each div with class one
If there is only one child element under the div parent element with class one, then select this child element
Form object attribute filter selector
This selector mainly filters the selected form elements
Form object attribute filter selector example
Use the val() method of the jQuery object to change the value of the available elements in the form Use the val() method of the jQuery object to change the value of the unavailable elements in the form
Use the length property of the jQuery object to get the number of selected multi-select boxes
Use the text() method of the jQuery object to obtain the content selected in the drop-down box
Form Selector
The above is all about the jQuery filter selector. It is very detailed. I hope it will be helpful to my friends.