JSFiddle - React, Tailwind, and code Playground
by Dineshkani
HTML
<div id="firstdiv">
<div id="secondiv">
Hello world
</div>
</div>
JavaScript
//jquery
alert($("#firstdiv").text()); //Gets only the text within the element
//Note .html() will show all the HTML element inside your selector but .text() shows only the text in your selector.
//Javascript
alert(document.getElementById("secondiv").textContent); //Gets only the text within the element.
//Note .innerHTML will show all the HTML element inside your selector but .textContent show only the text.