JSFiddle - React, Tailwind, and code Playground
HTML
<input type="button" value="create School" onclick="createSchool();" />
<br>
<div id="school">
</div>
CSS
#school {
display: inline-table;
vertical-align: middle;
text-align: left;
}
#h1 {
font-size: 50px;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans - serif;
}
JavaScript
function createSchool() {
var school = new School(1);
}
function School(id) {
this.id = id;
Unload_School();
function Unload_School() {
var div = document.createElement("div");
div.id = "school";
var h1 = document.createElement("h1");
h1.id = "h11";
h1.style.color = "red";
var title = document.createTextNode("High School");
h1.appendChild(title);
// I use here but not work
var elem1=document.getElementById("h11");
addEvent(elem1, "click", function(){edit(this);});
var h3 = document.createElement("h3");
h3.style.color = "blue";
var subtitle = document.createTextNode("List Of Students:");
h3.appendChild(subtitle);
div.appendChild(h1);
div.appendChild(h3);
document.body.appendChild(div);
};
}
function addEvent(obj, evType, fn) {
try {
console.log('addevent');
obj.addEventListener(evType, fn, false);
} catch (e) {console.log(e);}
try {
console.log('addevent2');
obj.attachEvent("on" + evType, fn);
} catch (e) {}
}
function edit(param) {
var elem = param;
var input = document.createElement("input");
input.setAttribute("type", "text");
input.setAttribute("value", elem.firstChild.nodeValue);
removeChildren(elem);
elem.appendChild(input);
input.focus();
input.select();
addEvent(input, "blur", function() {
removeChildren(elem);
elem.appendChild(document.createTextNode(input.value));
});
}
function removeChildren(param) {
for (var i = 0, elem; elem = param.childNodes[i]; i++) {
elem.parentNode.removeChild(elem);
}
}