How to use jQuery .html() to get the HTML contents of HTML element

1 Answer

0 votes
<!doctype html>
<html>
<head>
  <script src="js/jquery/1.11.3/jquery.min.js"></script>
</head>
<body>

<p>
  <b>Click</b> here to view the <span id="tag">html</span> code
</p>
<script>
$("p").click(function() {
  var htmlCode = $( this ).html();
  $( this ).text( htmlCode );
});

/*
run:

<B>Click</B> here to view the <SPAN id=tag>html</SPAN> code 

*/
</script>
</body>
</html>

 



answered Aug 20, 2016 by avibootz
...