jQuery wrapInner() wrap around Paragraph

Introduction

Wrap a <b> element 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>//from   w ww . java2  s . c o m
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").wrapInner(function(){
      return "<b></b>"
    });
  });
});
</script>
</head>
<body>

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

<button>wrap</button>

</body>
</html>



PreviousNext

Related