Move and insert the div element before each p element using prependTo() - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:prependTo

Description

Move and insert the div element before each p element using prependTo()

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials