Answer the question
In order to leave comments, you need to log in
How to get the contents of a div with a wrap?
There is a div, the content of which is edited by the user himself, such as poking at it and typing
But, if it has a line break, then when its content (innerHTM, innerText) is received, undefined pops up
How to avoid this?
Answer the question
In order to leave comments, you need to log in
<div id="content_wrapper">
<div id="content" contenteditable="true">
Текст
<br>
текст
</div>
</div>
<button id="get_content">Получить текст</button>
<script>
document.addEventListener('DOMContentLoaded', () => {
get_content.addEventListener('click', () => {
alert(content_wrapper.querySelector('#content').innerHTML);
});
});
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question