Home
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script> $(document).ready(function () { $("button").click(function () { //get div text var txt = $("div").text(); alert("Content of div tag: " + txt); //set p text $("p.test").text('Changed Text using text()') }); }); </script> </head> <body> <h1>jQuery Manipulation Methods: text()</h1> <div> This is div. </div> <p class="test">This is a paragraph</p> <button>Click Me to test text()</button> </body> </html>
Result: