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 () { $("p").map(function (index) { return $(this).text('New Paragraph ' + (++index)); }); }); }); </script> </head> <body> <h1>jQuery DOM Traversing Methods: map()</h1> <div id="myDiv"> <p>Paragraph 1</p> <p>Paragraph 2</p> <p>Paragraph 3</p> <p>Paragraph 4</p> </div> <button>Click Here to Test .map()</button> </body> </html>
Result: