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 () { $('<span>This is a span tag - added using insertBefore()</b>').insertBefore('p'); $('<p style="color: red">This is a paragraph - added using insertBefore()</p>').insertBefore(".myCls"); }); </script> </head> <body> <h1>jQuery Manipulation Methods: insertBefore()</h1> <p>This is paragraph.</p> <div class="myCls" style="border:1px solid red;"> This is div. </div> </body> </html>
Result: