How to "create" HTML elements via Javascript? -
perhaps there's better way word question saying "dynamically create dom elements via javascript", decided write simple title in case latter wrong. anyway, there way can "spawn" html elements via javascript? example, can click button on site, , paragraph appear?
you can use createelement()
this:
var el = docment.createelement("elementtype");
this create element, if replace elementtype
type of element ("div", "p", etc.)
after that, can use native .appendchild()
or .insertbefore()
methods on whichever element want attach new created element onto.
var attachto = document.getelementbyid('appendtome'); attachto.appendchild(el);
and it'll on page after last element inside of element.
references:
Comments
Post a Comment