Operation of the DOM node

Source: Internet
Author: User

operation of the DOM node--jqueryInternal Insert 1, (end) Append method, Appendto method (to facilitate chained operation) (beginning) Prepend method

$ (' #div1 ').    Append ($ (' #div2 '));  //Insert the DIV2 into the end of the Div1    
?
$ (' #div1 '). appendto ($ (//) Insert Div1 at the end of the Div2   
?
$ (' #div1 ').    prepend ($ (' #div2 '));  //Insert the DIV2 into the beginning of the Div1    
?
$ (' #div1 '). prependto ($ (//) insert Div1 into the beginning of div2   
External operation () after method, before method

() InsertAfter method, InsertBefore method

$ (' #h2 '). After ($ (//Insert Div2 to the end of H2   
?
$ (' #h2 '). before ($ (//Insert Div2 in front of H2   
Wrapping method Wrap Method Replace Method ReplaceWith () method can be filled in the label
$ (' #div1 '). replacewith ($ (    
$ (' #div2 ').    ReplaceAll ($ (' #div1 '));  
Delete
$ (' #div1 ').    empty ();  //Delete the contents of Div1  
?
Copy Clone filter

Filter

EQ ()  //Select one, result for jquery object  note with get () distinguished, get (), result as native object
First ()  //Get the number one
Get the last one
Hasclass (' class name ')  //Yes, return, true  No, return false 
?
Event handling (bubbling phase)
Binding events
function  fn () {
  Console. log (  
}
?
$ (' P '). On (' click ',fn);   
?
Unbind Event
$ (' P '). Off (' click ',fn);   
?
?
Page Load Completion events
$ (document). Ready (function () {  
  
})
Event delegate
Ul. onclick=function (event) {   
  if (event.  Taget. nodeName= = =LI) {    
Console. log (event.  Taget. 
  }
}
?
?
$ (' #ul '). On (' click ',' li ',function () {    
  Console. log ($ (this).  HTML ());   
})

Operation of the DOM node

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.