Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, so the createTreeWalker method is the RIGHT way of doing this and it's a good way. I unfortunately needed to do this to support IE8 which does not support document.createTreeWalker. Sad Ian is sad.</p> <p>If you want to do this with a .replace on the page text using a non-standard innerHTML call like a naughty child, you need to be careful because it WILL replace text inside a tag, leading to XSS vulnerabilities and general destruction of your page.</p> <p>What you need to do is only replace text OUTSIDE of tag, which I matched with:</p> <pre><code>var search_re = new RegExp("(?:&gt;[^&lt;]*)(" + stringToReplace + ")(?:[^&gt;]*&lt;)", "gi"); </code></pre> <p>gross, isn't it. you may want to mitigate any slowness by replacing some results and then sticking the rest in a <code>setTimeout</code> call like so:</p> <pre><code>// replace some chunk of stuff, the first section of your page works nicely // if you happen to have that organization // setTimeout(function() { /* replace the rest */ }, 10); </code></pre> <p>which will return immediately after replacing the first chunk, letting your page continue with its happy life. for your replace calls, you're also going to want to replace large chunks in a temp string </p> <pre><code>var tmp = element.innerHTML.replace(search_re, whatever); /* more replace calls, maybe this is in a for loop, i don't know what you're doing */ element.innerHTML = tmp; </code></pre> <p>so as to minimize reflows (when the page recalculates positioning and re-renders everything). for large pages, this can be slow unless you're careful, hence the optimization pointers. again, don't do this unless you absolutely need to. use the createTreeWalker method zetlen has kindly posted above..</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload