JavaScript Tutorial/jQuery/replaceWith
Replace text with
<source lang="javascript">
<html>
<head> <script type="text/javascript" src="js/jquery-1.3.2.js"></script> <script type="text/javascript"> $(document).ready(function(){$("p").replaceWith("
" + $(this).text() + "
");
}); </script> <style> div { border:2px green solid;} </style> </head> <body> <body>
Hello
</body>
</html></source>
Replace with another tag
<source lang="javascript">
<html>
<head> <script type="text/javascript" src="js/jquery-1.3.2.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("p").replaceWith("Paragraph. ");
}); </script> <style> div { border:2px green solid;} </style> </head> <body> <body>
Hello
</body>
</html></source>
replaceWith(content): Replaces all matched elements with the specified HTML or DOM elements.
<source lang="javascript">
<html>
<head> <script type="text/javascript" src="js/jquery-1.3.2.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function () {$(this).replaceWith("
" + $(this).text() + "
");
}); }); </script>
</head> <body> <body> <button>First</button> </body>
</html></source>