TAG
CSS
JavaScript
Result
Run
License
<p class="para"> <span>Lorem Ipsum</span> is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. </p> <textarea id="textcontent"></textarea> <button type="button" id="btn">Set TextContent</button>
.para > span { font-weight: bold; color: red; } .para + textarea { width: 100%; height: 100px; }
window.addEventListener("load", function() { const $elParagraph = document.querySelector(".para"); const $elTextContent = document.getElementById("textcontent"); const $elBtn = document.getElementById("btn"); const $elSpan = $elParagraph.querySelector("span"); $elTextContent.value = $elParagraph.innerHTML; $elBtn.addEventListener("click", () => { $elSpan.outerText = $elSpan.textContent; $elTextContent.value = $elParagraph.innerHTML; }); });
Console
expand_less
License
License
by DevDic
Close