<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery Get HTML Contents of an Element</title> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script> $(document).ready(function(){ $(".btn-one").click(function(){ var str = $("p").html(); alert(str); }); $(".btn-two").click(function(){ var str = $("#container").html(); alert(str); }); }); </script> </head> <body> <button type="button" class="btn-one">Get Paragraph</button> <button type="button" class="btn-two">Get Container</button> <div id="container"> <h1>Happy Morning!</h1> <p>This is a very <strong>Impotant</strong> paragraph.</p> </div> </body> </html>