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 monkeyswhen 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 <strong>monkeys</strong> 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
Post a Comment