jquery infinite level create DOM node

Source: Internet
Author: User

Code implementation:

vardata=[{"tag": "UL", "attr": {"Class": "Ban_nav", "id": "Ban"},            "Child":[                {"Tag": "Li",                    "Child":[                        {"Tag": "A", "attr": {"href": "activenet.html", "target": "_blank"},                            "Child":[                                {"Text": "First", "tag": "Span"},                                {"Text": "Second", "tag": "Span"},                                {"Text": "Third", "tag": "Span"},                            ]                        },                        {"Tag": "A", "attr": {"href": "activenet.html", "target": "_blank"},                            "Child":[                                {"Tag": "IMG", "attr": {"src": "Images/banner5.png"}},                                {"Tag": "IMG", "attr": {"src": "Images/banner5.png"}},                                {"Tag": "IMG", "attr": {"src": "Images/banner5.png"}}                            ]                        }                    ]                },                {"Tag": "Li",                    "Child":[                        {"Tag": "A", "attr": {"href": "activenet.html", "target": "_blank"},                            "Child":[                                {"Tag": "IMG", "attr": {"src": "Images/activenet/banner.png"}}                            ]                        }                    ]                } ]        },        {"Tag": ' A '}        ]                $(function() {SetData (' Banner ', data); })        functionSetData (name,data) {varl=$ (' <span/> ')); CreateDOM (data,l) $ (' Coder[name= ' ' +name+ ' "] '). HTML (l); }        /** Infinite Level creation DOM node * @param {object} opt Parameter Object * @param {object} parent container*/        functionCreateDOM (opt,parent) {$.each (opt,function(k,v) {var_e={},l; /*when there is content to be assigned, some are not as follows: IMG*/v[' Text ' && (_e.text=v[' text ')]); /*assignment occurs when an attribute is present, with key/value pairing*/v[' attr ' && (_e=$.extend ({},_e,v[' attr ')])); /*creating a DOM node*/L=v.tag? $ (' < ' +v[' tag ']+ '/> ', _e): v[' text '];                Parent.append (l); /*recursive when a child node is present*/                if(v[' child ']) {createdom (v[' Child '],l);        }            }); }
View Code

HTML section:

<coder name= "banner" ></coder>

jquery infinite level create 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.