Self-encapsulated Operation Dom Method

Source: Internet
Author: User

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>Document</title></Head><Body><DivID= "D1">    <DivID= "D1_1"></Div>    <DivID= "D1_2"></Div></Div><DivID= "D2">Hello<DivID= "D2_1">I'm a dog.</Div>    <DivID= "D2_2"></Div></Div><Table><TR><P><TDID= "haha">haha</TD></P></TR></Table><Scripttype= "Text/javascript">varMylibs={first:function(elem) {returnElem&&(Elem.firstelementchild||elem.firstchild); }, Last:function(elem) {returnElem&&(Elem.lastelementchild||elem.lastchild); }, Prev:function(elem) {returnElem&&(elem.previouselementsibling||elem.previoussibling); }, Next:function(elem) {returnElem&&(elem.nextelementsibling||elem.nextsibling); }, before:function(newelement,targetelement) {returntargetelement&&Targetelement.parentnode?TargetElement.parentNode.insertBefore (newelement,targetelement):NULL; }, after:function(newelement,targetelement) {returntargetelement&&  This. Last (targetelement)==targetelement?             //if the last node is the target element, it is added directly. Because the default is the last             This. Before (newelement,targetelement)://if it is not, it is inserted in front of the next sibling node of the target element. Which is behind the target element.             This. Before (Newelement, This. Next (targetelement)); }, replace:function(elem,newelement,oldelement) {}, remove:function(elem) {returnElem.parentNode.removeChild (Elem); }, Empty:function(elem) {elem.innerhtml= "'; returnElem; }, Append:function(elem,newelement) {returnElem.appendchild (newelement); }, Text:function(elem,value) {returnvalue===undefined?elem.textcontent||Elem.innerHTML.replace (/<[^<]+>/G,"')                :             This. Append ( This. Empty (Elem), (Elem&&elem.ownerdocument||document). createTextNode (value)); }, HTML:function(elem,value) {if(Value===undefined&&Elem.nodetype=== 1)             returnelem.innerhtml; if(typeofvalue=== 'string' && /< (?: Script|style|link)/i.test (value)) {Value=Value.replace (/< (?! Area|br|col|embed|hr|img|input|link|meta|param) (([\w:]+) [^>]*] \/>/gi,'<$1></$2>'); Elem.innerhtml=value; }        if(elem) { This. Append ( This. Empty (Elem), value); }    }    /*append ()-insert content at the end of the selected element prepend ()-insert content at the beginning of the selected element after ()-insert content after the selected element before ()-in Remove ()-delete the selected element (and its child elements) empty ()-*/};vardom1=document.getElementById ('D1'), Dom2=document.getElementById ('D2');vartmp=Document.createelement ('Div'); Console.log (Mylibs.after (TMP,DOM2));</Script></Body></HTML>

Self-encapsulated Operation Dom Method

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.