In the development of Web front-end, often encountered some data or type can not be determined before running the situation, at this time, the data display, with the help of dynamic creation of HTML elements to show.
The common way to dynamically create HTML elements is as follows, roughly the same!
HTML functions:
1 var elehtml = "<div id= ' newone ' > XXX </div> '"; 2 jQuery (your_specified_selector). HTML (elehtml)
Append function:
1 var elehtml = "<div id= ' Newone ' >xxx</div>"; 2 jQuery (your_specified_selector). Append (elehtml);
Appendto function:
var elehtml = "<div id= ' Newone ' >xxx</div>", JQuery. ( elehtml). AppendTo (your_specified_selector);
However, the dynamic existence of HTML elements, there is no way through the regular click function to give jquery to its binding function response, need to be implemented in the following way (the following is an example of the fragment code in my Project):
1 $ ("#userinfopanel"). Click (function(e) {2 if($ (E.target). is ("# Clear ")) {3 //your logic4 }else{ 5 // your logic 6 } 7 }
In addition, jquery Validate has no way of verifying the legitimacy of dynamically generated HTML form elements. Need to implement it yourself.
Dynamically create HTML elements based on jquery