Wrap a div element around the p element - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:wrap

Description

Wrap a div element around the p element

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(){
        $("p").wrap(function(){
              return "<div></div>"
        });/*from  w ww .j  ava 2s .  c  o  m*/
    });
});
</script>
<style>
div {
    background-color: yellow;
    padding: 10px;
}
</style>
</head>
<body>

<p>This is a paragraph.</p>

<button>test</button>

</body>
</html>

Related Tutorials