jquery Learning Summary of the elements of relative positioning and selector (continuous update) _jquery

Source: Internet
Author: User
The relative positioning of the ①jquery element.
In jquery, not only can absolute positioning be done using selectors, but also relative positioning, as long as the second parameter is specified in $ (), and the second parameter is the relative element. When the second parameter passes a jquery object, the relative selection of the datum is relative to the object.
Copy Code code as follows:

Relative positioning and selector of <title>jquery elements </title>
<script type= "Text/javascript" src= "Jquery-1.4.2.js" ></script>
<script>
$ (function () {
Set the background color of line 1th to 3rd to red (absolute positioning).
Note that the GT (0) here starts with the serial number in the new sequence from LT (4), not the original. (That is, further filtering on the original basis)
$ ("#t tr:lt (4): GT (0)"). CSS ("Background", "Red");
$ ("#t tr"). Click (function () {
$ (this) in This-->jquery in DOM
$ ("TD", $ (this)) is relative to the line TR under the search TD
$ ("TD", $ (this)). CSS ("Background", "green");
});
$ ("tr[title=ttt]"). CSS ("Background", "yellow");
});
</script>
<body>
<div id= "Div1" >
<table id= "T" >
<tr><td>111</td><td>A</td></tr>
<tr><td>222</td><td>B</td></tr>
<tr><td>333</td><td>C</td></tr>
<tr><td>444</td><td>D</td></tr>
<tr title= "TTT" ><td>555</td><td>E</td></tr>
<tr><td>666</td><td>F</td></tr>
<tr><td>777</td><td>G</td></tr>
<tr><td>888</td><td>H</td></tr>
<tr><td>999</td><td>I</td></tr>
</table>
<br/>
</div>
</body>

Run Effect chart:

②$ ("Div[id]") Select div with id attribute
③$ ("div[Title=test] Select the div with the title property "Test".Note: an equal sign.
$ ("Div[title!=Test] "to select a div with the title property not" test "
④$ ("input:checked")Note: There is no space between input and: checked
⑤The difference between $ ("input") and $ (": Input")
$ ("input") can only be taken to the <input> label, and <textarea>, <select>, etc. cannot be obtained.
$ (": input") not only takes the <input> label, but also the forms of the <textarea>, <select>, and other submitting servers.
A similar $ (": Text") gets all Single-line text boxes, and we can do the same with $ ("Input[type=text]"). Similarly, there are $ (":p assowrd"), $ (": Radio"), $ (": CheckBox"), $ (": Submit"), $ (": Image"), $ (": Reset"), $ (": Button"), $ (": File"), $ ( ": Hidden")
⑥ uses the attr () method to read or set the attributes of an element, operating with attr for encapsulated properties that are not in jquery.
$ ("#a: A"). attr ("href", "http://baidu.com");
⑦ Deletes the property removeattr, deletes the attribute in the source code to see, at this time and clears the attribute the difference.
⑧ dynamically create a DOM node
uses the $ (HTML string) to dynamically create a DOM node, returns a JQuery object, and then calls methods such as append to add the created node to the DOM.
var link=$ ("<a href= ' http://www.baidu.com ' > Baidu </a>");
$ ("Div:first"). Append (link); The
Append method is used to append an element (add child element to last child element) at the end of an element
Prepend method to add elements (add child elements, become the first child element) at the beginning of an element
after method add elements after element (add sibling)
The Before method adds an element (add sibling) before the element
⑨ Delete node
Remove () deletes the selected node, which is the returned node object and can continue to use the deleted node.
 var list=$ ("#ulLeft li.test"). Remove ();
 $ ("#ulRight"). Append (list);

Block event bubbling e.stoppropagation ();
Block default behavior: E.preventdefault () is the same as Window.event.returnvalue=false effect

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.