Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery Add Elements to DOM</title> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("p").prepend("<h1>This is a heading</h1>"); }); }); </script> </head> <body> <p>This is a paragraph.</p> <button>Add heading</button> </body> </html>