How to dynamically create element with javascript

This is how to dynamically create an elementwith javascript:
<script>
newEl = document.createElement('div') //creates a div element
newEl.setAttribute('id','newlayer') // set the attribute id for the created element to 'newlayer', any other attribute can be set that way
document.body.appentChild(newEl)
</script>

No comments:

Post a Comment