[jQuery] Re: find and replace
Use a regex: $('body').html( $('body').html().replace(/(got|the)/g,'$1') ); On Apr 28, 9:39 am, kazim mehdi wrote: > hi > by using the following code i am able to find only first occurrences > of the keywords can anyone help me to make it work for all of the > occurrences. > > thank you > > function test() > { > var keywords = ["got", "the"]; > var el = $("body"); > $(keywords).each(function() > { > el.html(el.html().replace(this, > ""+this+"")); > }); > > }
[jQuery] Re: find and replace
Use a regex: $('body').html( $('body').html().replace(/(that|your)/g,'$1') ); On Apr 28, 9:39 am, kazim mehdi wrote: > hi > by using the following code i am able to find only first occurrences > of the keywords can anyone help me to make it work for all of the > occurrences. > > thank you > > function test() > { > var keywords = ["got", "the"]; > var el = $("body"); > $(keywords).each(function() > { > el.html(el.html().replace(this, > ""+this+"")); > }); > > }
[jQuery] Re: Find and replace character inside div
I think you would be best off with a Regular Expression: var f = $("#fruits"); f.html( f.html().replace(/;/g,"") ); "/g enables "global" matching. When using the replace() method, specify this modifier to replace all matches, rather than only the first one." http://www.regular-expressions.info/javascript.html On Apr 10, 11:23 pm, jc_2009 wrote: > Hi, > > How to do a find and replace with Jquery. > > For example... > > Current: > Apple;Banana;Orange;Peach > > I want it to look like this: > AppleBananaOrangePeach > > I found and tried this code but it only does the first one. I don't > know how to loop it. > > var f = $('#fruits'); > f.html(f.html().replace(";", "")); > > Any help would be appreciated. Thanks!
[jQuery] Re: Find and replace character inside div
You'll probably want to set the "global" flag and use regex notation. var f = $('#fruits'); f.html(f.html().replace(/;/g, "")); --Karl Karl Swedberg www.englishrules.com www.learningjquery.com On Apr 10, 2009, at 5:23 PM, jc_2009 wrote: Hi, How to do a find and replace with Jquery. For example... Current: Apple;Banana;Orange;Peach I want it to look like this: AppleBananaOrangePeach I found and tried this code but it only does the first one. I don't know how to loop it. var f = $('#fruits'); f.html(f.html().replace(";", "")); Any help would be appreciated. Thanks!
[jQuery] Re: Find and replace image problem
Okay, how about something like: reg = new RegExp('/'+imagename+'$/', 'gi'); new_src = $(this).attr("src").replace(reg, fileObj.name); On Mar 18, 10:00 am, Chris K wrote: > As I said that doesn't work. > > On Mar 18, 11:48 am, James wrote: > > > var new_src = $(this).attr("src").replace(imagename, fileObj.name); > > > will store the String value of that into new_src, so you just set your > > image source to it. > > > $(this).attr("src", new_src); > > > On Mar 18, 7:56 am, Chris K wrote: > > > > I have the image name in a variable and want to replace it but not > > > sure how to do this. > > > > Currently I can replace the image src with: > > > var new_src = $(this).attr("src").replace(/ship.png$/i, fileObj.name); > > > > I want to do something like this (which doesn't work): > > > var new_src = $(this).attr("src").replace(imagename, fileObj.name); > > > > Any help is appreciated. > > > > Chris > >
[jQuery] Re: Find and replace image problem
As I said that doesn't work. On Mar 18, 11:48 am, James wrote: > var new_src = $(this).attr("src").replace(imagename, fileObj.name); > > will store the String value of that into new_src, so you just set your > image source to it. > > $(this).attr("src", new_src); > > On Mar 18, 7:56 am, Chris K wrote: > > > I have the image name in a variable and want to replace it but not > > sure how to do this. > > > Currently I can replace the image src with: > > var new_src = $(this).attr("src").replace(/ship.png$/i, fileObj.name); > > > I want to do something like this (which doesn't work): > > var new_src = $(this).attr("src").replace(imagename, fileObj.name); > > > Any help is appreciated. > > > Chris
[jQuery] Re: Find and replace image problem
var new_src = $(this).attr("src").replace(imagename, fileObj.name); will store the String value of that into new_src, so you just set your image source to it. $(this).attr("src", new_src); On Mar 18, 7:56 am, Chris K wrote: > I have the image name in a variable and want to replace it but not > sure how to do this. > > Currently I can replace the image src with: > var new_src = $(this).attr("src").replace(/ship.png$/i, fileObj.name); > > I want to do something like this (which doesn't work): > var new_src = $(this).attr("src").replace(imagename, fileObj.name); > > Any help is appreciated. > > Chris
[jQuery] Re: find and replace text in a variable
for(var i = 1; i <= materias_num; i++){ $("#fd_opcoes").append(loop.replace(/1/g,''+i)); } On Dec 13, 7:18 pm, Marcelo Wolfgang <[EMAIL PROTECTED]> wrote: > Hi all, > > I've a form with a numeric drop down ( from 1 to 10 ) and when the > user select a number from it, I want to add the corresponding number > of textfields in my code, but I need to change the input name and I > can't figure out how to do that this is what I have right now > > $("#add_opcoes").change(function (){ > var materias_num = this.value; > var loop = $("#fd_opcoes").html() > $("#fd_opcoes").empty() > for(var i = 1; i <= materias_num; i++){ > $("#fd_opcoes").append(loop); > } > > }); > > and this is what is inside loop > > > Material 1: > > > > what I want is to change all the 1 that are inside the variable with i > from the looping ( so it will be 1, 2 ...10 ) > > is there a way to do that easily or should I look at other options ? > > TIA > Marcelo Wolfgang