Search code examples
javascriptcsssyntaxhtmlhighlighting

Periodically detecting specific strings inside of an HTML element


I have a div element with contenteditable set to true, and I want to detect whether a certain string exists within the element, and if so, style it, giving the appearance of syntax highlighting (I've already looked at existing libraries/scripts, and none of them work the way I need them to).

What would be the best solution to this, while preserving compatibility with HTML5/CSS3 compliant browsers?


Solution

  • jQuery is nearly always a good choice IMO, and here's a very lightweight plugin for it that I think does just what you're looking for.

    http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html