JQuery selector xpath syntax Application

Source: Internet
Author: User

For example, the following html code
Copy codeThe Code is as follows:
<Ul>
<Li class = "aaaa" title = "ttt"> li-1 </li>
<Li class = "bbbb"> li-2 </li>
<Li title = "fffff"> li-2 </li>
</Ul>
& Lt; div class = & lt; aaaa & gt; title = & lt; ttt
Li-2 <div class = "bbbb"> </div>
<Div title = "fffff"> li-2 </div>


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 class = "aaaa" title = "ttt"> li-1 </li>
<Li title = "fffff"> li-2 </li>
& Lt; div class = & lt; aaaa & gt; title = & lt; ttt
<Div title = "fffff"> li-2 </div>

$ ("Div [@ title]"). click ()..........

Select all elements with title under all div labels
That is
& Lt; div class = & lt; aaaa & gt; title = & lt; ttt
<Div title = "fffff"> li-2 </div>

Second, select E [@ attr = val] based on the attribute value.

$ ("Div [@ title = ttt]"). click ()................

Select all the elements under the div whose title attribute is equal to ttt.
That is
<Div class = "aaaa" title = "ttt"> li-1 </div>

If it is $ ("[@ title = ttt]"). click ()................

All elements whose attribute title is ttt
<Li class = "aaaa" title = "ttt"> li-1 </li>
& Lt; div class = & lt; aaaa & gt; title = & lt; ttt

Third, select E [@ attr ^ = val] based on the Start Letter of the attribute value.

$ ("Div [@ title ^ = t]"). click ()................

All attribute title values under all div elements start with t


Third, select E [@ attr $ = val] based on the Start Letter of the attribute value.

$ ("Div [@ title $ = t]"). click ()................

All attribute title values under all div elements end with t

Third, select E [@ attr * = val] based on the characters in the attribute.

$ ("Div [@ title * = t]"). click ()................

All attribute title values under all div elements are all elements that contain t

Third, select E [@ attr = val] [@ attr = val] based on multiple attributes.

$ ("Div [@ title = ttt] [@ class = aaaa]"). click ()................

All attribute title values under all div elements are equal to ttt and the attribute class is equal to aaaa.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.