Hello, You can insert html inside the element elem.innerHTMl = html;
And how to insert it next? (before / after all the difference) Without creating an additional wrapper
Big thank you
Hello, You can insert html inside the element elem.innerHTMl = html;
And how to insert it next? (before / after all the difference) Without creating an additional wrapper
Big thank you
I threw an example using this function , although I was a little confused by her status of Working Draft :
var elem = document.getElementById('elem'); function pasteAfterEnd() { elem.insertAdjacentHTML('afterend', '<p>Абзац 100</p>'); } function pasteBefore() { elem.insertAdjacentHTML('afterbegin', '<p>Абзац 0</p>'); } function pasteAfter() { elem.insertAdjacentHTML('beforeend', '<p>Абзац 3</p>'); } #elem { background: #ccc; } <div id="elem"> <p>Абзац 1</p> <p>Абзац 2</p> </div> <button onclick="pasteAfterEnd()">Вставить рядом</button> <button onclick="pasteBefore()">Вставить перед</button> <button onclick="pasteAfter()">Вставить после</button> 'beforebegin' and 'afterend' , and the method is the same. - Qwertiy ♦ var elem = document.getElementById('elem'), // поиск нужного элемента p = document.createElement('p'); // создание "вставляемого" элемента p.innerHTML = '0'; // наполнение его контентом elem.parentElement.insertBefore(p,elem); // добавление контента через родителя <p>1</p> <p>2</p> <p id="elem">3</p> <p>4</p> <p>5</p> Source: https://ru.stackoverflow.com/questions/598605/
All Articles