jQuery <p> wrap paragraph content with <b>

Description

jQuery <p> wrap paragraph content with <b>

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Wrapping HTML Around the Elements in jQuery</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
    // Wrap paragraph's content on button click
    $("button").click(function(){
        $("p").contents().wrap("<em><b></b></em>");
    });//from   ww w . j a  v  a  2s .c  o m


});
</script>
<style>
    .wrapper{
        padding: 20px;
        background: #f0e68c;
        margin: 10px 0;
    }
    .container{
        padding: 15px;
        background: #fff;
        font-size: 24px;
    }
</style>
</head>
<body>
    <button type="button">Wrap Demo Text</button>
    <div class="container">
        <p>This is demo text.</p>
    </div>
</body>
</html>



PreviousNext

Related