function add() {
var e_type = document.createElement("p");
var p_type = document.getElementById("self");
var text = document.createTextNode("I am a slow walker, but I never walk back.");
e_type.appendChild(text);
p_type.appendChild(e_type);
var pattribute = document.createAttribute("id");
pattribute.value = "test";
element.setAttributeNode(pattribute);
}
#test {
color: blue;
font-style: bold;
}
<div id="self">
<p>Hello, Thought of the Day</p>
</div>
<button onclick="add()">Click me</button>
:- Added element text color is not changing by the use of createAttribute but rest of the tag are changing their color which are using this ID(test).
setAttribute('name', 'value')instead.