jQuery <div> wrap div container with another div on document ready

Description

jQuery <div> wrap div container with another div on document ready

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 div container with another div on document ready
    $(".container").wrap('<div class="wrapper"></div>');


});/*from  w w  w .  j ava2  s.  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