Answer the question
In order to leave comments, you need to log in
How to implement a replacement in the code of the page according to the dictionary in JavaScript?
Tell me how to correctly implement the replacement of a string in the html page code (after loading into the browser) with an expression from a dictionary. And how to properly organize the storage of this dictionary (in the future, I plan to load the dictionary from a JSON request).
For example, the dictionary contains the entry:
var dict = {
'Невский 123': '<a href="http://maps.yandex.ru/...">Невский пр., д. 123</a>',
'Санкт-Петербург': '<a href="www.visit-petersburg.ru/ru">Санкт-Петербург</a>',
};
<p>Адрес: Невский 123</p>
<p>Адрес: <a href="http://maps.yandex.ru/...">Невский пр., д. 123</a></p>
Answer the question
In order to leave comments, you need to log in
I think that it is necessary to store as a key not the phrase that needs to be replaced, but the id of the element.
I don't really understand what the id has to do with it? There are some expressions on the page that need to be replaced with some other expressions. For example, if it says St. Petersburg, it should be replaced with the link <a href=' www.visit-petersburg.ru/ru '>St. Petersburg</a>, because the key 'St. Petersburg' is in the dictionary.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question