I.T. Discussion Community!
-Collapse +Expand
Search JavaScript Group:

-Collapse +Expand JavaScript Store

Prestwood eMagazine

October Edition
Subscribe now! It's Free!
Enter your email:

   ► KBWebsite Scri...JavaScript a...   Print This     
  From the October 2015 Issue of Prestwood eMag
JavaScript and AJAX:
Posted 13 years ago on 10/19/2007 and updated 6/18/2008
JavaScript Code Snippet:
 A flashcard from our JavaScript Flashcards Library
 A code snippet from our JavaScript Code Snippets Page


Implements replaceAll in javascript. This is achieved using prototype.js

Syntax Example:

Add this between the head tags (replace [[ with < and ]] with >):

[[script type="text/javascript" src="prototype.js"]] [[/script]]

Here's the code (replace [[ with < and ]] with >):

[[script type="text/javascript"]]
// define your replace all function like this 
String.prototype.replaceAll=function(s1, s2) 
{return this.split(s1).join(s2)}; 
// use your replaceAll function like this
var replacedText = text2replace.replaceAll("-what to replace-",
		" -with what to replace- "); 


Share a thought or comment...
Write a Comment...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.

Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P115A1
Enter key:
Code Contributed By bhavyait:
Visit Profile

 KB Article #100700 Counter
Since 4/2/2008

Follow PrestwoodBoards on: 

©1995-2020 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech