jQuery text()
Get Text inside an Element
<!DOCTYPE html> <html lang="en"> <head> <title>jQuery Get Element's Text Content</title> <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> <script> $(document).ready(function(){ // Show text content of plain paragraph $(".show-plain-text").click(function(){ document.getElementById("demo").innerHTML = $(".plain").text(); });// w w w. ja v a2 s . c o m // Show text content of formatted paragraph $(".show-formatted-text").click(function(){ document.getElementById("demo").innerHTML = $(".formatted").text(); }); }); </script> </head> <body> <p id="demo"></p> <p class="plain">The quick brown fox jumps over the lazy dog.</p> <p class="formatted">The <strong>quick</strong> brown fox <em><sup>jumps</sup></em> over the <a href="#">lazy dog</a>.</p> <button type="button" class="show-plain-text">Get Plain Text</button> <button type="button" class="show-formatted-text">Get Formatted Text</button> </body> </html>