The flaws of jquery innerHTML

Source: Internet
Author: User
Tags jquery innerhtml
The creation of innerHTML is a very efficient interface for nodes. jquery uses innerHTML on node operations, creating efficiencies that are at least 2-10 times faster than createelement, and can generate a bunch of nodes at a single point, but there are some compatibility issues.
I have summed up the following points, of course, compatible with the jquery solution as well.
IE will be the user string Trimleft operation, the user may be the intention is to need a blank IE8 some elements innerHTML is read-only IE will ignore the beginning of the scope of the element does not execute script scripts, of course, if support defer IE9 before the bangs Besides, some labels cannot be used as child elements of a div, such as TR,TB, col, etc.
The node operations of jquery ultimately need to be translated into document fragmentation, which is done through the Buildfragment () method, so innerHTML compatible fixes are also naturally in buildfragment methods. We figure out why and then analyze it, but the whole code is simple.
1: First no scope problem, through the document fragment to create a div containing container, so that all elements are included in the DIV element, including Script,style, and other elements of the domain, a good solution to the TMP = TMP fragment.appendchild ( Context.createelement ("div")); tmp.innerhtml = Elem
2: For the element that does not support the innerHTML attribute, give it separately, through the regular extraction to this node name to deal with Wrapmap = {tr: [2, <table><tbody>, "</tbody></t Able> "],} tag =/< ([\w:]+)/.exec (' <tr> Resource Network </tr> ') wrap = Wrapmap[tag] Wrapmap._default; tmp.innerhtml = wrap[1] + elem.replace (rxhtmltag, "<$1></$2>") + wrap[2]; If you encounter a label for wrapmap[' tr ', it automatically wraps a layer of nodes, which is supported.

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.