javascript add div before element

Solutions on MaxInterview for javascript add div before element by the best coders in the world

showing results for - "javascript add div before element"
Luna
27 May 2018
1var my_elem = document.getElementById('my_id');
2
3var span = document.createElement('span');
4    span.innerHTML = '*';
5    span.className = 'asterisk';
6
7my_elem.parentNode.insertBefore(span, my_elem);