Change the tag with replaceWith and keep the text in jQuery
Description
The following code shows how to change the tag with replaceWith and keep the text.
Example
<html>
<head>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {<!--from ww w. j ava2 s .co m-->
$("p").replaceWith("<div>" + $(this).text() + "</div>");
});
</script>
<style>
div {
border: 2px green solid;
}
</style>
</head>
<body>
<p>Hello java2s.com</p>
</body>
</html>