.
This is the second paragraph .
This is the third paragraph.
Selector is very useful and will need to require every step while using jQuery. They receive the correct element when you want from your HTML document.
The following table lists the basic selectors and explains them by examples when you click and the corresponding link:
Example of Selector in jQuery
Similar to the above syntax and examples, the following examples will help you understand more about the different types of other useful Selectors.
Selector Description $ ('*')
This selector selects all elements in the document.
$ ("p> *")
This selector selects all elements that are children of a paragraph element.
$ ("# specialID")
This function Selector receives the element with id = "specialID"
$ (". specialClass")
This selector accepts all elements that have a class that is specialClass .
$ ("li: not (.myclass)")
Select all elements matched by the tag
$ ("a # specialID.specialClass")
This selector matches the link with an id being a specialID and a class that is specialClass .
$ ("p a.specialClass")
This selector matches a class that is specialClass declared in the element
.
$ ("ul li: first")
This selector only accepts elements
$ ("# container p")
Select all elements matched by
which is a child of an element with an id that is a container .
$ ("li> ul")
Select all elements matched by
$ ("strong + em")
Select all matching elements by following immediately an element he is matched by .
$ ("p ~ ul")
Select all elements matched by
.
$ ("code, em, strong")
Select all elements matched by or hoặc .
$ ("p strong, .myclass")
Select all elements matched by which are children of an element matched by
as well as all elements that have a class is myclass .
$ (": empty")
Select all elements without child elements.
$ ("p: empty")
Select all elements matched by
without child elements
$ ("div [p]")
Select all elements matched by
.
$ ("p [.myclass]")
Select all elements matched by
which contains an element with a class is myclass .
$ ("a [@rel]")
Select all matching elements by having a rel attribute.
$ ("input [@ name = myname]")
Select all matching elements by having a name value exactly equivalent to myname.
$ ("input [@ tên ^ = myname]")
Select all matching elements by having a name value starting with myname .
$ ("a [@ rel $ = self]")
Select all elements matched by which the end attribute value is self .
$ ("a [@ href * = domain.com]")
Select all elements matched by which has an href value containing domain.com.
$ ("li: even")
Select all elements matched by
$ ("tr: odd")
Select all matching elements by having an odd index value.
$ ("li: first")
Select element
$ ("li: last")
Select element
$ ("li: visible")
Select all elements matched by
$ ("li: hidden")
Select all elements matched by
$ (": radio")
Select all radio buttons in the Form.
$ (": checked")
Select all checked dialogs in Form.
$ (": input")
Select only form elements (input, select, textarea, button).
$ (": text")
Only select text elements (input [type = text]).
$ ("li: eq (2)")
Select element
$ ("li: eq (4)")
Select element
$ ("li: lt (2)")
Select all elements matched by
$ ("p: lt (3)")
Select all elements matched by
before the fourth element; In other words, choose three elements
Firstly.
$ ("li: gt (1)")
Select all elements matched by
$ ("p: gt (2)")
Select all elements matched by
after the third element.
$ ("div / p")
Select all elements matched by
which is a child of an element matched by
$ ("div // code")
Select all elements matched by mà là con của một phần tử được so khớp bởi
$ ("// p // a")
Select all elements matched by which are children of an element matched by
.
$ ("li: first-child")
Select all elements matched by
$ ("li: last-child")
Select all elements matched by
$ (": parent")
Select all elements that are the parent of another element, including text.
$ ("li: contains (second)")
Select all elements matched by
You can use all of these selectors with any HTML / XML element in the general way. For example, if the $ Selector ("li: first") works for the element
.
According to Tutorialspoint
Previous article: Basic about jQuery
Next article: Properties in jQuery