Home » jQuery28 January 2010

jQuery: How to replace string, div content and image src?

In this article, I will be showing you how you can replace string, div content, and image src value with jQuery.

You can do this by replace() function in jQuery.

View Demo || Download Code

Here is the code to replace string. This will replace the ‘smile’ text with ‘be happy’.

Here is the code to replace image src. The following code replaces ‘hills‘ with ‘sunset‘.

Here is the code to replace div content. The following code replaces the text ‘First‘ with ‘This is the first‘.

Here is the full source code:

View Demo || Download Code


php magento mukesh chapagain

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • Thanks its help full

  • What is the difference between java script replace and jquery replace

  • Antony492


  • How about if we do have many images to inter-swap? 

  • Very useful artice. Thanks for sharing.

  • Alcor

    Thanks, your article was helpful to me.