Home >Web Front-end >JS Tutorial >I will explain to you in detail how to create div, span, and label in js through code.
The following is what I have compiled for you on how to create div, span, and label in js. Interested students can take a look.
var newdiv=document.createElement("div"); newdiv.className="switch-animate switch-on" newdiv.id="switch_div" document.getElementById("dhcpd_div").appendChild(newdiv); var rinput = document.createElement("input"); rinput.setAttribute("type","checkbox"); rinput.setAttribute("name","dhcpd_name"); rinput.setAttribute("id",'dhcpd'); document.getElementById('switch_div').appendChild(rinput); rinput.setAttribute("checked",'checked'); var spanON = document.createElement("span"); spanON.className = "switch-left switch-success"; spanON.innerHTML = "ON"; document.getElementById("switch_div").appendChild(spanON); var label_var = document.createElement("label"); label_var.innerHTML = " "; document.getElementById("switch_div").appendChild(label_var); var spanOFF = document.createElement("span"); spanOFF.className = "switch-right switch-warning"; spanOFF.innerHTML = "OFF"; document.getElementById("switch_div").appendChild(spanOFF);
The above is how to create div, span, label in js. I hope it will be helpful to everyone in the future. .
Related articles:
How to establish a model data model in js (the code is provided, simple and easy to understand)
Native JS implementation method to determine collision (interesting example)
About simple calls to obtain JSON data in JS (code attached, simple and crude)
The above is the detailed content of I will explain to you in detail how to create div, span, and label in js through code.. For more information, please follow other related articles on the PHP Chinese website!