This article describes how to use the jQuery tag replacement function replaceWith (). You can use replaceWith to replace the tags in the template and implement multilingual websites. For more information, see
ReplaceWith for simple use
In jQuery, there is a powerful replacement function replaceWith (), which is very simple to use, such:
The page has the following p tags:
Replace all p tags with "#"
$('p').replaceWith('##');
Result After execution:
Replace tags
With this replaceWith, we can replace all p tags with B tags with the same content:
$('p').each(function(){ $(this).replaceWith(''+$(this).html()+'');});
Result
This is replaced!
Multilingual websites can use this function to easily complete
If you are developing a multi-language website, you can even use this feature. For example, add an I tag to the text you want to translate and then traverse the translation to replace it.
Assume that the dom structure of the page is as follows:
We need to translate the text in the I tag on the page. The I tags on the page are apple and computer. Therefore, we need a translation Library:
Var translate = {'apple': 'apple', 'pc '};
Then I can perform translation replacement in this way.
$('i').each(function(){ $(this).replaceWith(translate[$(this).html()]);});
Effect after execution:
Page effect: