The jquery Selector is a very important part of the jquery library.
jquery Selector is used to select an HTML element whose base statement is the same as the CSS selector (Selector), and all jquery Selector begin with $ ().
Select HTML tags
The way to select an HTML element is to use the tag name of the element directly, such as selecting all <p> elements
The following example hides all <p> elements when the user taps a button
$ (document). Ready (function () { $ ("button"). Click (function () { $ ("P"). Hide ();
#id Select
The JQuery #id selector is used to select the element that defines the id attribute, and the ID of the element on the page should be guaranteed to be unique, and you can use the ID to select a single unique element.
For example, when a button is clicked, only the element with ID test is hidden.
<! DOCTYPE html>
. class SelectorThe jQuery. Class selector selects all elements that define the class attribute for the set value, such as the following example to hide all elements with the class name test:
<! DOCTYPE html>
More examples
Grammar |
Description |
$ ("*") |
Select So element |
$ (This) |
Select Current Element |
$ ("P.intro") |
Option P element for all Class=intro |
$ ("P:first") |
Select the first P element |
$ ("ul Li:first") |
Select the first <li> element of the first <ul> element |
$ ("ul Li:first-child") |
Select the first element of each <ul> |
$ ("[href]") |
Select all elements with an HREF |
$ ("a[target= ' _blank ')") |
Select a element for all Target=_blank |
$ ("a[target!= ' _blank ')") |
Select All target! The A element of =_blank |
$ (": Button") |
Select All button elements and elements with input type button |
$ ("Tr:even") |
Select all even rows <tr> elements |
$ ("tr:odd") |
Select all singular lines <tr> elements
|