Answer the question
In order to leave comments, you need to log in
How to find and replace multiple occurrences in text with one script?
there is such a construction that allows you to find and replace a certain occurrence in html - a word or a sentence - with another one on the fly.
$("body").children().each(function() {
$(this).html($(this).html().replace(/old text/g,"new text"));
});
Answer the question
In order to leave comments, you need to log in
const replacements = [
[ 'вот это надо заменить', 'вот на это' ],
[ 'а это заменить', 'на вот это' ],
];
$elements.html((i, html) => {
return replacements.reduce((acc, n) => acc.replace(RegExp(n[0], 'g'), n[1]), html);
});
The easiest thing is not to sweat.
Something like this, I wrote without testing, but I hope the idea is understandable
const replacePairs= {'было1': 'стало1', 'было2': 'стало2', 'было3': 'стало3'};
$("body").children().each(function() {
let currentNode = $(this);
for (const pair in replacePairs) {
currentNode.html(currentNode.html().replace(/`${pair}`/g, `${replacePairs[pair]}`));
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question