JQuery selector xpath syntax _ _jquery

Source: Internet
Author: User
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


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.
    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.