{"id":1303,"date":"2012-09-28T14:13:56","date_gmt":"2012-09-28T14:13:56","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=1303"},"modified":"2012-09-28T14:13:56","modified_gmt":"2012-09-28T14:13:56","slug":"jquery-string-replace-find-replace-string-using-jquery-examples","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/jquery-string-replace-find-replace-string-using-jquery-examples\/","title":{"rendered":"jQuery String Replace Examples (includes Find &#038; Replace String)"},"content":{"rendered":"<p>Many a times, you may have come across a situation where a particular piece of text in an article of a page is unnecessary or need to be removed\/replaced with another string, or with empty spaces, etc. This could be of great help when you are dealing with data, that is accompanied by some default data &amp; you need to get rid of this default data. So in this article, I am going to share very simple ways (with examples) to perform a <em><strong>string replace using using jQuery<\/strong><\/em> i.e.<em><strong> find and replace string using jQuery<\/strong><\/em>. Read on to find out more.<!--more--><\/p>\n<h2>Examples to perform String Replace using jQuery<\/h2>\n<p>As the name suggest &#8220;jQuery string replace&#8221;, we will need a piece of string to work with. So let&#8217;s see how we can do find and replace in a string using jQuery.<\/p>\n<h3>Example 1:\u00a0Find &amp; Replace String with Space using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">&lt;script type=\"text\/javascript\"&gt;\n\nvar string = 'This is some text.';\n\n\/\/Replace text with space\nvar new_string = string.replace('some', ' ');\n\nalert(string + '\\n' + new_string);\n\n&lt;\/script&gt;<\/pre>\n<h3>Example 2:\u00a0Find &amp; Replace String with new\/another word using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">&lt;script type=\"text\/javascript\"&gt;\n\nvar string = 'This is some text.';\n\n\/\/Replace word with new word\nvar new_string = string.replace('some', 'new');\n\nalert(string + '\\n' + new_string);\n\n&lt;\/script&gt;<\/pre>\n<h3>Example 3:\u00a0Find &amp; Remove a Word using jQuery<\/h3>\n<pre class=\"lang:js decode:true\">&lt;script type=\"text\/javascript\"&gt;\n\nvar string = 'This is some text.';\n\n\/\/Simply remove a word\nvar new_string = string.replace('some', '');\n\nalert(string + '\\n' + new_string);\n\n&lt;\/script&gt;<\/pre>\n<h3>Example 4:\u00a0Find &amp; Remove a Word from a Textbox\/ Textbox value using jQuery<\/h3>\n<p>Lets assume that you have a Textbox on a page with ID &#8220;my_textbox&#8221; and it contains the value &#8216;This is some text&#8217;. Now you want to remove the word &#8220;some&#8221; from the textbox value using jQuery. You can do it like so.<\/p>\n<pre class=\"lang:js decode:true\">&lt;script type=\"text\/javascript\"&gt;\n\n\/\/Read the value of the textbox into a string\nvar string = $(\"#my_textbox\").val();\n\/\/Simply remove the word word 'some'\nvar new_string = string.replace('some', '');\n\nalert(string + '\\n' + new_string);\n\/\/If you want to replace the existing value of the textbox with the new string value, then you may do this:\n$(\"#my_textbox\").val(new_string);\n&lt;\/script&gt;<\/pre>\n<h5>Simple, isn&#8217;t it?<\/h5>\n<p>Do you know of any other ways to <strong>find and replace string using jQuery<\/strong>? Feel free to suggest by commenting below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Many a times, you may have come across a situation where a particular piece of text in an article of a page is unnecessary or need to be removed\/replaced with another string, or with empty spaces, etc. This could be of great help when you are dealing with data, that is accompanied by some default [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":395,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[20,13],"tags":[41],"class_list":["post-1303","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jquery-tips-and-tricks","category-tips-and-tricks","tag-jquery-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-l1","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/1303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/comments?post=1303"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/1303\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/media?parent=1303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=1303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=1303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}