JavaScript's jquery Selector

Source: Internet
Author: User

It's good to understand that when we chose to do DOM selection before, we used theDocment.getelementbyid () ,document.getElementsByTagName(),等。

Such code, in general, is available, but if there is a hierarchical relationship, we always need a recursive selection in this case. For example:

For example, to find <table class="green"> all inside <tr> , a layer of loops is actually wrong, because <table> the standard notation is:

<table>    <tbody>        <tr>...</tr>        <tr>...</tr>    </tbody> </table>

Obviously, we have to do a for nesting before we can find all the TR tags.

Jquery

A jquery object, which is a label group, similar to an array.

jquery Lookup Method:

Select the specified element using the jquery selector: 1. Choose only JavaScript2. Select Erlang3. Select JavaScript and ERLANG4. Select all programming languages 5. Select the name input6. Select the message and name input<!-- HTML structure--><div id= "Test-jquery" > <p id= "para-1" class= "color-red" >JavaScript</p> <p id= "para -2 "class=" Color-green ">Haskell</p> <p class=" color-red color-green ">Erlang</p> <p name=" Nam E "class=" Color-black ">Python</p> <form class=" test-form "target=" _blank "action=" #0 "onsubmit=" return false; " > <legend> Register new users </legend> <fieldset> <p><label> name: <input name = "name" ></label></p> <p><label> Mail: <input name= "Email" ></label></p&gt            ; <p><label> Password: <input name= "password" type= "password" ></label></p> <p><bu Tton type= "Submit" > Registration </button></p> </fieldset> </form></div>

Generally find, all with $ (' xxxxxx '), where xxxxxx is the specific screening scheme. The solution is as follows.

var js=$ (' #para-1 ');                               Find Var erl=$ ('. Color-red.color-green ') by name;               Through class search, both meet color-red and meet Color-greenvar jserl=$ ('. color-red ');                         Class lookup,  as Long  as  it contains color-red, will be looked for Var allcpl=$ (' #test-jquery>p ');                    All the  P-Tagged VAT nameinput=$ (' input[name= ' name ') under the ' Test-jquery ' tab;             The first is an  input, then name to meet the VAT nameinput=$ (' input[name= ' name "],input[name=" email "]);    It's a input,name, name or email.

  



JavaScript's jquery Selector

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.