We will explain several common usage of xpath in JQuery selectors based on examples, such as the following html code
The Code is as follows:
Li-1
Li-2
Li-2
First, select E [@ attr] based on the attributes.
$ ("[@ Title]"). click ()..........
That is, select all elements with a title attribute in the element.
That is
Li-1
Li-2
Li-1
Li-2
$ ("P [@ title]"). click ()..........
Select all elements with title under all p tags
That is
Li-1
Li-2
Second, select E [@ attr = val] based on the attribute value.
$ ("P [@ title = ttt]"). click ()................
Select all the elements with the title attribute equal to ttt under p.
That is
Li-1
If it is $ ("[@ title = ttt]"). click ()................
All elements whose attribute title is ttt
Li-1
Li-1
Third, select E [@ attr ^ = val] based on the Start Letter of the attribute value.
$ ("P [@ title ^ = t]"). click ()................
All attribute title values under all p elements start with t
Third, select E [@ attr $ = val] based on the Start Letter of the attribute value.
$ ("P [@ title $ = t]"). click ()................
All attribute title values of all p elements end with t
Third, select E [@ attr * = val] based on the characters in the attribute.
$ ("P [@ title * = t]"). click ()................
All attribute title values under all p elements are all elements that contain t
Third, select E [@ attr = val] [@ attr = val] based on multiple attributes.
$ ("P [@ title = ttt] [@ class = aaaa]"). click ()................
All attribute title values of all p elements are equal to ttt and the attribute class is equal to aaaa.