Remove a word in a text using jquery

In this programming tutorial we will learn how to remove a word in a text using jquery. Jquery is very powerful and we can achieve this task quite easily in it with the help of built-in replace() function. Let's have a look over the following code snippet that illustrates how to do so.
Remove a word in a text using jquery

<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
	<div id="myDiv">Welcome to nice-tutorials.blogspot.com</div>

<script langiage="javascript" type="text/javascript">
var el = $("#myDiv");
//replace(/word to remove/ig, "");
el.html(el.html().replace(/to/ig, ""));
</script>

</body>
</html>
In the above given example we are removing the word to from div's inner html, so the output will be

Output:-
Welcome nice-tutorials.blogspot.com

So that's it. This is the process to remove a word in a text using jquery.

I always love your feedback.

Stay tune with nice-tutorials.blogspot.com for millions of tutorials of jquery :)

0 comments: