2

I tried to use DomSanitizer.bypassSecurityTrustHtml, the html content looks as below:

<div>
  <div id="test-div">
    It is a test div element.
  </div>
  <script>
    function changeColor() {
      document.getElementById('test-div').style.background='red';
    }
    changeColor();
  </script>
</div>

Everything works here except the script tag code. Any leads are highly appreciated.

4
  • Does this answer your question? Angular - How to apply [ngStyle] conditions Commented Apr 14, 2023 at 6:10
  • @NarenMurali Please read the title carefully. Commented Apr 14, 2023 at 6:14
  • 1
    Take a look on this stackoverflow.com/a/46825383 Commented Apr 14, 2023 at 8:07
  • 1
    any idea why does prevent the script tag from being executed ? Commented Oct 20, 2024 at 15:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.