javascript - How to use html tags in <pre> when updated from the script -


i have text <pre id="printed-table">bunch of monkeys</pre>. want process text javascript window.onload highlight word monkeys.

so, should

bunch of monkeys
when page loaded.

i have script

<script type="text/javascript">   window.onload = function() {     var p = document.getelementbyid("printed-table");     var t = p.firstchild.nodevalue;     p.firstchild.nodevalue = t.replace(/monkeys/gmi, function(a) { return "<strong>" + + "</strong>"; } ) }  </script> 

but when page loads looks

bunch of &lt;strong&gt;monkeys&lt;/strong&gt; 

what missing?

thank you.

try setting p.innerhtml instead of p.firstchild.nodevalue. if do, you'll set actual html contents of element instead of (text) value of text node inside <pre> element.

  window.onload = function() {      var p = document.getelementbyid("printed-table");      var t = p.firstchild.nodevalue;      p.innerhtml = t.replace(/monkeys/gmi, function(a) {        return "<strong>" + + "</strong>"; } ) } 
 <pre id="printed-table">bunch of monkeys</pre>


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -