jquery Learning Notes Creation DOM element _jquery

Source: Internet
Author: User

Using the DOM method to create an element node, it is often troublesome to use document.createelement (), document.createTextNode (), AppendChild () in conjunction.

And jquery uses $ to create DOM elements directly

Copy Code code as follows:

var ONEWP = $ ("<p> content created with jquery </p>");

The above code is equivalent to JavaScript

Copy Code code as follows:

var oNewP2 = document.createelement ("P");
var otext = document.createTextNode ("This is the content created using the JavaScript method");
Onewp2.appendchild (Otext);

Example: Using jquery to create Dom

Copy Code code as follows:

<script type= "Text/javascript" >
$ (function () {
var ONEWP = $ ("<p> content created with jquery </p>");
Onewp.insertafter ("#display"); InsertAfter method
})

</script>
<div id= "Display" ></div>

Using jquery greatly shortens the length of your code. Save time for writing. I hope this article can give small friends some tips, have questions please give me a message.

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.