JQuery selector XPath syntax application _jquery

Source: Internet
Author: User
Like the following HTML code
Copy Code code as follows:

<ul>
<li class= "AAAA" title= "TTT" >li-1</li>
<li class= "BBBB" >li-2</li>
<li title= "FFFFF" >li-2</li>
</ul>
<div class= "AAAA" title= "TTT" >li-1</div>
<div class= "BBBB" >li-2</div>
<div title= "FFFFF" >li-2</div>


The first is to select E[@attr] based on the attribute
$ ("[@title]"). Click () ...

That is, select elements within all elements with title
That
<li class= "AAAA" title= "TTT" >li-1</li>
<li title= "FFFFF" >li-2</li>
<div class= "AAAA" title= "TTT" >li-1</div>
<div title= "FFFFF" >li-2</div>

$ ("div[@title]"). Click () ...

Select all the element with title under All div tags
That
<div class= "AAAA" title= "TTT" >li-1</div>
<div title= "FFFFF" >li-2</div>

The second chooses e[@attr =val] based on the value of the attribute .

$ ("div[@title =ttt]"). Click () .......

Select all the title attributes under div equal to TTT elements
That
<div class= "AAAA" title= "TTT" >li-1</div>

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

element with title equal to TTT under all elements
<li class= "AAAA" title= "TTT" >li-1</li>
<div class= "AAAA" title= "TTT" >li-1</div>

The third type selects e[@attr ^=val] based on the value of the attribute.

$ ("div[@title ^=t]"). Click () .......

All the attribute title values under all DIV elements are elements that start with T


The third type selects e[@attr $=val] based on the value of the attribute.

$ ("div[@title $=t]"). Click () .......

All the attribute title values under all DIV elements are elements that end with T

The third includes the letter selection based on the attribute value e[@attr *=val]

$ ("div[@title *=t]"). Click () .......

All the attribute title values under all DIV elements are all elements that contain t

The third option is to 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 attribute class equals AAAA elements

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.