Home > Web Front-end > JS Tutorial > body text

jQuery learning summary: relative positioning and selectors of elements (continuously updated)_jquery

WBOY
Release: 2016-05-16 18:07:24
Original
1072 people have browsed it

① Relative positioning of jQuery elements.
In jQuery, you can not only use selectors for absolute positioning, but also relative positioning. As long as the second parameter is specified in $(), the second parameter is the relative element. The second parameter is passed a jQuery object, and relative selection is performed relative to this object.

Copy code The code is as follows:



Relative positioning and selectors of jQuery elements

<script> <br>$(function(){ <br>//Set the background color of lines 1~3 to red (absolute positioning). <br>//Note the gt(0 here ) starts from the sequence number in the new sequence from lt(4), not the original one (that is, further filtering based on the original one) <br>$("#t tr:lt(4):gt(0). )").css("background","red"); <br>$("#t tr").click(function(){ <br>//This in Dom-->jQuery in $( this) <br>//$("td",$(this)) is relative to the search under tr of this line. td <br>$("td",$(this)).css("background"," green"); <br>}); <br>$("tr[title=ttt ]").css("background","yellow"); <br>}); <br></script>




< td>111 ;
;D



/td>
A
333C
555E
666F
777G
888H
I








Operation rendering:

jQuery learning summary: relative positioning and selectors of elements (continuously updated)_jquery

②$("div[id]") selects the div with the id attribute
③$("div[title=test]") selects the div with the title attribute "test". Note: an equal sign.
$("div[title!=test]")Select a div whose title attribute is not "test"
④$("input:checked")Note : There is no space between input and :checked
The difference between $("input") and $(":input")
$("input") can only be obtained tag, but