Enhance Usability by Highlighting Search Terms

by Matt Riggott, Brian Suda

27 Reader Comments

Back to the Article
  1. Nice script, but when your search term includes a German “Umlaut” like “ü” (ü), all text vanishes!

    Also I got strange results when the searched text includes several <div>s, <!—comments—>, and <?php ?> tags, don’t know which is responsible. Then the first <div> block is ignored and only text in the second is highlighted…

    Copy & paste the code below to embed this comment.
  2. Highlighting is nice if the words you were looking for are in an obscure part of the page. However, it quickly becomes annoying when the searched words are very common in the main text. Precisely because those words stand out, it gets very hard to read the rest.

    Copy & paste the code below to embed this comment.
  3. I’d recommend using XML/DOM parser instead of risky and costly regular expressions. And here you go – another advantage of using valid XHTML.

    Copy & paste the code below to embed this comment.
  4. congratulations for the article.

    Copy & paste the code below to embed this comment.
  5. Copy & paste the code below to embed this comment.
  6. Rather than defining colors to use for highlighting, you can use css colors to automatically specify whichever colors the browser uses by default for highlighting. Look here: http://bombingpixels.com/css/testing/css-user-interface.htm

    Copy & paste the code below to embed this comment.
  7. “Gracias” in inglés es “Thanks” no “Congratulations”.

    Copy & paste the code below to embed this comment.