This article describes the method of dynamically creating html elements by JavaScript and jquery. Share it for your reference, as follows:
Create elements
Create a select
var select = ("select"); [0] = new Option("Add-in 1", "value1"); [1] = new Option("Add-in 2", "value2"); = "2"; (select);
Create a div
var openDiv = ("div"); = "div3D"; = w+"px"; = h+"px"; = strHtml; (openDiv);
Create elements
function CreateDom() { var select = $("<select/>").appendTo($("body")); var option1 = $("<option value=\"1\">text1</option>").appendTo(select); var option2 = $("<option value=\"2\">text2</option>").appendTo(select); var option3 = $("<option value=\"3\">text3</option>").appendTo(select); var text = $("<input type=\"text\">").css({ "width": "150px", "border": "1px lightgrey solid" }).appendTo($("body")); var checkbox = $("<input type=\"checkbox\" />").appendTo($("body")); var ul = $("<ul/>").appendTo($("body")); var li = $("<li>li1</li>").appendTo(ul); var li = $("<li>li2</li>").appendTo(ul); }
For more information about JavaScript, readers who are interested in reading this site's special topic:Summary of JavaScript switching effects and techniques》、《Summary of JavaScript search algorithm skills》、《Summary of JavaScript animation special effects and techniques》、《Summary of JavaScript Errors and Debugging Skills》、《Summary of JavaScript data structure and algorithm techniques》、《JavaScript traversal algorithm and skills summary"and"Summary of JavaScript mathematical operations usage》
I hope this article will be helpful to everyone's JavaScript programming.