jQuery Replace Single or Double Quotes

Sam Deering
Tweet

Simple jQuery code snippets to replace single quotes and replace double quotes using the jQuery.replace function that takes two parameters. First the global search for all quotes (either single or double) and then a blank space to replace them (change the second parameter if you wish to replace them with something else – this code just removes them).

//replace all single quotes
var myStr = myStr.replace(/'/g, '');

//replace all double quotes
var myStr = myStr.replace(/"/g, '');

//or abit of fun, replace single quotes with double quotes
var myStr = myStr.replace(/'/g, '"');

//or vice versa, replace double quotes with single quotes
var myStr = myStr.replace(/"/g, ''');

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • Parveen Verma

    It’s a great post ….thanks

  • Kenneth M. Kolano

    Um, there is no JQuery here?