Relative positioning and Selector of elements in jquery learning Summary-continuous updating

Source: Internet
Author: User

① relative positioning of jquery elements.
In jquery, you can not only use the selector to perform absolute positioning, but also perform relative positioning, if you specify the second parameter in $ (), the second parameter is the relative element. When the second parameter is passed to a jquery object, the parameter is selected relative to the object as the benchmark.

<HTML> 

Run:

② $ ("Div [ID]") Select the DIV with the ID attribute
③ $ ("Div [ Title = test ] ") Select the DIV whose title attribute is" 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.
⑤ Difference between $ ("input") and $ (": Input ")
$ ("Input") can only obtain the <input> label, but <textarea>, <SELECT>, and so on cannot be obtained.
$ (": Input") not only can get the <input> label, but can get the form from the submit server such as <textarea> and <SELECT>.
Similarly, you can use $ ("input [type = text]") to obtain all single-line text boxes. For example, $ (": passowrd"), $ (": Radio"), $ (": checkbox"), $ (": Submit"), and $ (": image "), $ (": reset "), $ (": button "), $ (": file "), $ (": hidden ")
⑥ Use the ATTR () method to read or set the attributes of an element, and use ATTR to operate encapsulation attributes not available in jquery.
$ ("# A: First"). ATTR ("href", "http://baidu.com ");
7. Delete the removeattr attribute. Source code Cannot see, the difference between this and clearing properties.
⑧ Dynamically create DOM nodes
Use $ (HTML string) to dynamically create a DOM node, return a jquery object, and call the append method 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 to the end of an element (add a child element to become the last child element)
The prepend method adds an element (add a child element to become the first child element) at the beginning of the element)
The After method adds an element after the element (add brother)
Before method adds an element before the element (add brother)
⑨ Delete a node
Remove () deletes the selected node. This method returns the deleted Node object and can continue to use the deleted node.
VaR list = $ ("# ulleft Li. test"). Remove ();
$ ("# Ulright"). append (list );

Prevent event bubblesE. stoppropagation ();
Block default behavior: E. preventdefault () and window. event. returnvalue = false have the same 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.