I'm trying to get a grasp on html and javascript and wondering if there is a functional difference between using document.createElement(some_tag) vs <some tag></some tag>. I can see how using javascript's create element might make it easy to create the specific element over and over in different pages/sections of the website (instead of copying and pasting and making your code bulky). But is it bad practice/bad for memory or something to use create element.
For instance, consider the following code:
function createhtml() {
var li1 = document.createElement("li");
var text1 = document.createTextNode("First List Item");
li1.appendChild(text1);
var ul1 = document.createElement("ul");
ul1.appendChild(li1);
document.body.appendChild(ul1);
}Run Code Online (Sandbox Code Playgroud)
<body onload="createhtml()">
</body>Run Code Online (Sandbox Code Playgroud)
Is it better to do that, or simply:
<ul>
<li>First List Item </li>
</ul>Run Code Online (Sandbox Code Playgroud)
或者它们是否完全相同,而第二个只是更容易/更快地输入。