This post is written by guest blogger Aamir Hasan
Yesterday someone asked me how to replace a word in a text using jQuery. To demonstrate that, let us read text from a Div control, replace it with our text and then assign the replaced text to that Div, as shown in below example:
Note: This code will replace only the first occurrence of the word.
<html xmlns="http://www.w3.org/1999/xhtml" >
<title>Replace Word in a Text using jQuery</title>
<div id="div1">My name is aamir</div><br />
<input id="btnReplace" type="button" value="Replace" />
See a Live Demo
Aamir Hasan, is a Sr. Software Engineer and Technical Lead in a US based firm, having five years of experiences working in Software Design, Web Development, Consultancy and Training, using SQL Server and .NET Framework. He is an SEO professional too. He is capable of coordinating off-shore high level web development projects.