In this article we are going to discuss about how to change text inside any HTML content by using jQuery.
Below is the sample code to change text of any HTML element.
<html>
<head>
<title>This is jquery example to replace the texts</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
//This is for replaicing all text
$('#parentid').text('This is simple text after using jquery');
});
</script>
</head>
<body>
<div id="parentid">
This is simple text before using jquery
<div>This is child element</div>
</div>
</body>
</html>
$('#parentid').text('This is simple text after using jquery') is changing the text of HTML element whose id is "parentid". Here we are using text() jQuery function to change the text of HTML element.
Download source code: change text.zip (35.64 kb)