Answer the question
In order to leave comments, you need to log in
How to wrap everything that comes after a div?
There is a div followed by text and other elements.
<div class="block">Some text</div>
<hr>
More text
<br>
Again more text
Answer the question
In order to leave comments, you need to log in
const block = document.querySelector('.block');
const parent = block.parentNode;
const childNodes = [...parent.childNodes];
const wrapper = document.createElement('div');
wrapper.classList.add('another__block');
wrapper.append(...childNodes.slice(childNodes.indexOf(block) + 1));
parent.append(wrapper);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question