Javascript examples for jQuery Method and Property:prependTo
Move and insert the div element before each p element using prependTo()
<!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").prependTo("p"); });/*from w ww .j a va 2 s .co m*/ }); </script> </head> <body> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <div>Hello world!</div> <button>test</button> </body> </html>