0

I have an html page in which the user will be able to insert custom HTML content. For instance, it could be something like this:

<div class='main-container'>
   <div class='previous-stuff'>
        ...
    </div>
    <div class='custom-content'>
        {Custom content from user}
    </div>
    <div class='next-stuff'>
        ...
    </div>
</div>

I used document.querySelector('custom-content').innerHtml = customContent to set the content. If the custom content has a unclosed div, for instance, it will mess up with the rest of the page.

Is there any way to "shield" the rest of the page from problems from the custom content?

I don't think its relevant, but the page is a WordPress page.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Marlon
  • 1,719
  • 3
  • 20
  • 42
  • possible duplicate of https://stackoverflow.com/questions/6234773/can-i-escape-html-special-chars-in-javascript – Silvan Jun 15 '20 at 21:20
  • 1
    I think you can take a look at https://stackoverflow.com/a/14216406/8583669. Also don't forget to **disable javascript's code** or user will be able to run javascript on your website – johannchopin Jun 15 '20 at 21:21

0 Answers0