Could you suggest a script that replaces all defined domain name names in an HTML document with a specific id ?

Ie, for example, is available on the page in different places of option value form

 <option value="http://site.ru">текст</option> 

and you need the script to display the following form:

 <option value="http://mysite.ru?http://site.ru">текст</option> 

I would be grateful for the help.

  • one
    @ gera43, If you are given an exhaustive answer, mark it as correct (click on the check mark next to the selected answer). - Nicolas Chabanovsky

1 answer 1

 jQuery("option").each(function(){ var string = jQuery(this).val(); var regexp = "site.ru"; var result = "mysite.ru? http://site.ru "; string = string.replace(regexp, result); jQuery(this).val(string); }); 

Whole page:

 var code= jQuery("body").html(); var regexp = "site.ru"; var result = "mysite.ru? http://site.ru "; code = code.replace(regexp, result); jQuery("body").html(code); 
  • Nick777, thank you very much, but it does not come out, but do not tell me how then to make the replacement of all mentions on site.ru in the entire html file? - gera43
  • There was a mistake in the code, now corrected. - nick777