A summary of common methods for creating HTML elements dynamically in jquery _jquery

Source: Internet
Author: User

The examples in this article describe the common ways in which jquery dynamically creates HTML elements that are useful when using jquery for Web programming. Share to everyone for your reference. The specific methods are as follows:

In general, you can create HTML elements dynamically in the following ways:

1, use jquery to create the syntax of the elements
2, the dynamic content into the array, and then traverse the array dynamic creation of HTML elements
3, the use of template

1. Append to the jquery object using the jquery dynamic creation element.

 <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
   <title></title>
   <script src=" Scripts/jquery-1.10.2.js "></" script>
   <script type= "Text/javascript" >
     $ (function () {
       $ (' <input/> ', {
         ID: ' CBX ',
         name: ' CBX ',
         type: ' checkbox ',
         checked: ' Checked ',
         click:function () {
           alert ("Dot Me ~ ~");
         }
       }). Appendto ($ (' #wrap ')
   ); </script>
  
 

The effect is as shown in the following illustration:

2. First put the content into the array, and then iterate through the array of HTML

  

The effect is as shown in the following illustration:

I believe that this article on the use of jquery for the web design has some reference value.

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.