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