Skip to content

Instantly share code, notes, and snippets.

@naveeninja
Created May 3, 2017 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naveeninja/83482f1579945a0e2181bad8e7c40bff to your computer and use it in GitHub Desktop.
Save naveeninja/83482f1579945a0e2181bad8e7c40bff to your computer and use it in GitHub Desktop.
Demo jQuery Replace
<html>
<head>
<title>Testing</title>
</head>
<body>
<h1><u>Demo jQuery Replace</u></h1>
Hello, this is a test replacing -9o0-9909 with <b>The new string</b>.
<br/><br/>
If I wrote -1o9-2202 and -1o9-2202 again but really wanted it to be <b>The ALL new string</b>.
<br/><br/>
This 12345-6789 wants to be <b>abcde-fghi</b>.
</body>
</html>
var replaced = $("body").html().replace('-9o0-9909','<b>The new string</b>');
$("body").html(replaced);
var replaced = $("body").html().replace(/-1o9-2202/g,'<b>The ALL new string</b>');
$("body").html(replaced);
$("body").html($("body").html().replace(/12345-6789/g,'<b>abcde-fghi</b>'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment