I want to create html element using JavaScript and add class or id, so I can edit this element later.
I know how to create element:
<html>
<body>
<div id="new">
<p id="p1">a</p>
<p id="p2">b</p>
</div>
<script>
var tag = document.createElement("p");
var text = document.createTextNode("c");
tag.appendChild(text);
var element = document.getElementById("new");
element.appendChild(tag);
</script>
</body>
</html>
But I don’t know how to add class or id to element that don’t have id or class at beggining.