Change all links at once

Is there any way to change all the links at once in the option tag?
Example:

<select size="1" name="links" onchange="window.location.href=this.value;"> <option value=" http://website.com/1001/">Blue</option> </select><br> <select size="1" name="links" onchange="window.location.href=this.value;"> <option value=" http://website.com/2001/">Red</option> </select><br> <select size="1" name="links" onchange="window.location.href=this.value;"> <option value=" http://website.com/3001/">Green</option> </select> 

.... And so on about 100 links.
Now I want to change the website.com link to m.website.com the furthur link remains the same. Like m.website.com/1001, m.website.com/1002

+6
source share
3 answers

try the following:

 $(function(){ $('select[name="links"] option').each(function(){ var val=$(this).val(); val=val.replace('http://','http://m.'); $(this).val(val); }); }); 

Demo

+6
source

The easiest way to do this is to simply find and replace all instances of http://website.com/ with http://m.website.com/

If there are some instances that you do not want to replace, you can use a regular expression to match the text. Sort of

Find

 (<option value=" http:\/\/)(website)(\.com\/\d+\/">.*?<\/option>) 

and replace with

 $1m.website$3 
0
source

Try the following:

 $(document).ready(function () { $('select[name="links"] option').each(function () { var val = $(this).val(); val = val.replace('website.com', 'm.website.com'); $(this).val(val); }); }); 
0
source

All Articles