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

Javascript examples for jQuery Method and Property:insertBefore

Description

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

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").insertBefore("p");
    });//w  w  w .j  a  v a2 s  .  c  o  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