How can i write this without using jQuery?
$('body').prepend('<div id="idC" style="display: none;" class=""><div id="idA">' + titelN + '</div></div>');
You should first learn how to create an element without using any library. Basically, there are some method for you to create element and append element to the document. They are createElement
, insertBefore
, appendChild
.
createElement ref: http://www.w3schools.com/jsref/met_document_createelement.asp
insertBefore ref: http://www.w3schools.com/jsref/met_node_insertbefore.asp
appendChild ref: http://www.w3schools.com/jsref/met_node_appendChild.asp
The code below should work for all browser. Try more and learn more.
var parent = document.createElement("div"); parent.id = "idC"; parent.style.display = "none"; var child = document.createElement("div"); child.id = "idA"; child.innerHTML = titelN; parent.appendChild(child); document.body.insertBefore(parent,document.body.childNodes[0]);
There is the insertAdjacentHTML
method, but it does not work in older FF versions:
document.body.insertAdjacentHTML('afterbegin', '<div id="idC" style="display: none;" class=""><div id="idA">' + titelN + '</div></div>');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With