jQuery <h1> add HTML before heading
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Inserting HTML Contents Before or After the Elements in jQuery</title> <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> <script> $(document).ready(function(){ // Add content before heading on button click $("button.insert-before").click(function(){ $("h1").before('<img src="image2.png" alt="Symbol">'); });// ww w .j a v a 2 s.c om }); </script> <style> h1{ display: inline-block; /* To place marker image and heading in one line */ } body{ text-align: center; } </style> </head> <body> <h1>Hello World</h1> <hr> <button type="button" class="insert-before">Insert Before</button> <button type="button" class="insert-after">Insert After</button> <hr> <div id="container"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> <p>Quis quam ut magna consequat faucibus. Pellentesque eget.</p> </div> </body> </html>