Javascript examples for jQuery Method and Property:insertBefore
Move and insert the div element before each p element using insertBefore()
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("div").insertBefore("p"); });//from ww w . ja va 2 s .com }); </script> </head> <body> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <div>Hello world!</div> <button>test</button> </body> </html>