The DOM operation of jquery

Source: Internet
Author: User

The DOM operation of JavaScript can be divided into three aspects: Dom Core (CORE), Html-dom and Css-dom

The method of inserting a node append () appends the contents of $ ("P") to the inside of each matching element. Append ("<b> Hello </b>")

AppendTo () Appends all matching elements to the specified element. $ ("<b> Hello!! </b> "). AppendTo (" P ")

Prepend () to each matched element to the predecessor content. $ ("P"). prepend ("<b> Hello </b>")

Prependto () adds a matching element to the specified element. $ ("<b> Hello! </b> ") prependto (" P ")

After () InsertAfter () before () InsertBefore ()

Delete node: jquery provides two ways to delete a node remove () and empty () $ ("ul Li:eq (1)"). Remove ();//gets to the second Li element and removes it from the Web page.

Empty () Strictly means that the node is deleted, but the node is emptied. He can empty all elements in the element $ ("ul Li:eq (1)"). empty (); Copy node $ (this). Clone (True). AppendTo ("body");

Replacement nodes ReplaceWith () and ReplaceAll ()

The ReplaceWith () method replaces all matching elements with the developed HTML or dom$ ("P"). ReplaceWith ("<b> What's your favorite fruit?" </b> ")

Change the contents of the original p into the specified content

Parcel nodes: Wrap the other tags with one node, and jquery provides wrap () and Warpall () and Warpinner ()
$ ("strong"). Warp ("<b></b>");//Use the B-tag to wrap the <strong> elements together


Property action: attr () gets and sets the attribute of the element $ ("P"). attr ("title") Gets the title property of P. $ ("P"). attr ("title", "You title") Set the Title Property removeattr () Delete the attribute of the element


Style actions: Get styles and set styles
$ ("P"). attr ("class") Gets the class $ ("P"). attr ("Class", "My Class") sets the class to MyClass append Style $ ("P"). AddClass ("another"); The difference between adding another's Class attribute style addclasss () and attr () AddClass is to add a class style, and attr () is changed on an existing basis.


Delete style; $ ("P"). Removeclass ("High") removes the name of the selected element as the High class Property $ ("P"). Removeclass ("high Another") removes the two class style $ ("P") for the selected element ). Removeclass () removes all the class properties of the selected element


Toggle Style: Toggle () $ ("DFDF"). Toggle (function () {//Operation style code 3},function () {//Operation style code 4} Alternating execution code 3 and code 4
Sets and gets the HTML text and value of the HTML () method $ ("P"). HTML ("<strong> What's your favorite fruit?" </strong> ") The text () method is equivalent to innertext in JavaScript and supports all browser Val () methods to get the value of the textbox

Traversing nodes

The children () method gets the child element next () method to get the sibling element immediately following the matching element. For example, the peer element of P element is ul Li's unordered list one way to get UL is $ ("P"). Next () The resulting value is the UL unordered List prev () method is the inverse method of the next () method siblings () method gets all the sibling elements before and after the matching element. There are many ways to get the nearest matching element to traverse a node without closet (). Find () filter () Nextall () Prevall () parent () parents ()

The DOM operation of jquery

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.