Create a DOM element instance using jQuery

Source: Internet
Author: User
This article mainly introduces jQuery's method for creating DOM elements. The example analyzes jQuery's skill of using $ to directly create DOM elements, which has some reference value, for more information about how to use jQuery to create DOM elements, see the following example. Share it with you for your reference. The specific analysis is as follows:

Using the DOM method to create element nodes usually requires the combination of document. createElement (), document. createTextNode (), and appendChild (), which is very troublesome.

JQuery uses $ to directly create DOM elements.

The code is as follows:

Var oNewP = $ ("

Content created using jQuery

");


The above code is equivalent to javascript

The code is as follows:

Var oNewP2 = document. createElement ("p ");
Var oText = document. createTextNode ("This is the content created using the javascript method ");
ONewP2.appendChild (oText );


Example: use jQuery to create a DOM

The code is as follows:

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.