CodeLab
Show Output
 
 
 
1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
<meta charset="utf-8">
5
<title>jQuery wrapInner()</title>
6
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
7
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
8
<style>
9
div{font-size:16px;height:40px;line-height:30px;width:300px;background:#11a286;padding:5px;color:#FFF;margin:0 0 10px 0}
10
</style>
11
<script>
12
$(document).ready(function() {
13
  $("#button").click(function() {
14
     $("p").wrapInner('<em></em>');
15
  });
16
});
17
</script>
18
</head>
19
<body>
20
 <p>This is a paragraph.</p>
21
 <button style="margin:0 0 10px 0;background:#e8e8e8;" class="btn" id="button">Click here to wrap emphasized element around the content of p element</button><br />
22
 </body>
23
</html>                            
 

Share this example with Facebook, Twitter