Injecting JS with XMP

The xmp element is obsolete, but supported by all browsers. You could also use the template element, but JavaScript would get executed in old browsers that do not support HTML5.

Here should the result of the injected JavaScript appear.

<div id="message"></div>

xmp {display: none;}

<xmp id="jsToInject">
   document.getElementById('message').innerHTML = 'Succesfully injected JavaScript'

if ('createRange' in document) {
  /* Modern browsers (IE9+, Chrome, Edge, Firefox, Safari, ...) */
  var jsString = document.getElementById('jsToInject').textContent
  var jsNode = document.createRange().createContextualFragment(jsString)
} else {
  /* Fallback for old browsers */
  var jsString = document.getElementById('jsToInject').innerHTML

<script> var i = document.getElementById('message') = '#dfd' i.innerHTML = '<ins>Succesfully injected JavaScript<\/ins>' </script>