jquery source of the empty and HTML (") difference

Source: Internet
Author: User
Tags return tag

Emptyfunction() {VarElem, i = 0;for (; (Elem =This[i])! =Null i++) {//Remove element nodes and prevent memory leaksif (Elem.nodetype = = = 1) {// loop erase data Jquery.cleandata (GetAll (Elem, false// remove child while (Elem.firstchild) {elem.removechild (elem.firstchild);} // If this was a select, ensure that it displays empty (#12336 ) // support:ie<9 if (Elem.options && jquery.nodename (elem, "select" )) {elem.options.length = 0
                             
                              ; }} 
                              return this;}, 
                              

In the code, all the data is erased first, so what does data contain?

The GetAll method finds all descendant elements. The GetAll code for jquery is as follows:

var strundefined =typeofUndefinedfunctionGetAll (context, tag) {VarElems, elem, i = 0, found =typeof Context.getelementsbytagname!== strundefined? Context.getelementsbytagname (Tag | | "*") :typeof Context.queryselectorall!== strundefined? Context.queryselectorall (Tag | | "*"): undefined; if (!  Found) { for (found = [], Elems = Context.childnodes | | context; (Elem = Elems[i])! = null; i++ ) { if (!tag | | Jquery.nodename (Elem, tag)) {Found.push (elem);} else {jquery.merge (found, getAll (Elem, Tag));}}} return tag = = = Undefined | | Tag && jquery.nodename (context, tag)? Jquery.merge ([context], found): found;} GetAll (Document.body,false);  htmlcollection Array              

The collection to which GetAll is taken, cleandata

    1. Removeevent the event, freeing the memory (jquery-bound events are saved in data), and the code below can find the list of events we have bound. Expando is the identity of each object in jquery that is not duplicated in the page. expando: "JQuery" + (version + Math.random ()). Replace (/\d/g, ""),
      $ (' body '). On (' click ',function() {    alert (' The IS Body ');}); Console.log ($.cache[$ (' body ') [0][$.expando]]);   
    2. Delete Internalkey (object ID), push ID to Deletedids

  

Simply empty, the first loop is to remove the bindings from the descendant elements, clear jquery to this Dom's cache, and loop removefirstchild.

and the HTML ("), is the simple brute force setting innerHTML = ';

Transferred from: http://www.cnblogs.com/henryli/archive/2014/02/25/3566461.html

jquery source of the empty and HTML (") difference

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.