jQuery wrapInner() wrap new created element

Introduction

Create a new b element and wrap around the content of each p element.

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/* www  . ja v  a 2s  .  co m*/
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").wrapInner(document.createElement("b"));
  });
});
</script>
</head>
<body>

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

<button>Do</button>

</body>
</html>



PreviousNext

Related