'Problem displaying document.body.innerHTML.replace

I add document.body.innerHTML to the page, but the results are displayed incorrectly in the inspect element!

I will add this code:

document.body.innerHTML = document.body.innerHTML.replace(/xxxxxxx/g, 'sssssssssss');

https://i.stack.imgur.com/cmcIW.png

But in the inspect element it shows this code:

document.body.innerHTML = document.body.innerHTML.replace(/sssssssssss/g, 'sssssssssss');

inspect element

Why does this happen?

I use datatables to display in the table, but I want to change the column title to another language



Solution 1:[1]

This is happening because the script is inside the body, so as a result, it is replacing all of that content in the script too. What you could do, is, put all of the front-end contents into a div element with a specific id. Then, get the innerHTML of that div, and it should work.

Have a good day!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Grayseon