Unrecognized Expression
Unrecognized Expression
I need to replace links on a page with some text and the link. A typical link looks like this:
<a class="xlat-en" href="../../bio/s/a/i/saillens_r.htm">Ruben Saillens</a>
When I run this code:
$(".xlat-en").each(function(index) {
translatorPhrase = "Traduit de l’anglais au français par %s";
var newHTML = translatorPhrase.replace('%s', this.outerHTML);
$(this).replaceWith(newHTML);
});
The desired result is an updated node that looks like this:
Traduit de l’anglais au français par
<a class="xlat-en" href="../../bio/s/a/i/saillens_r.htm">Ruben Saillens</a>
Instead, the replaceWith() call on the last line causes this error message:
Syntax error, unrecognized expression: %s
I tried enclosing the new HTML in a <span>, but got the same error.
Note: The translatorPhrase string above varies, depending on the language of the Web page. I included it here as a constant to simplify the example.