Way to highlight code in textarea with jquery?

No, there isn't. You can apply styles to the entire textarea, but not part of the text in it.

You would need something that works as a replacement for the textarea, here is a list of some.


You could use CodeMirror http://codemirror.net/

...a versatile text editor implemented in JavaScript for the browser. It is specialized for editing code, and comes with a number of language modes and addons that implement more advanced editing functionality.

A rich programming API and a CSS theming system are available for customizing CodeMirror to fit your application, and extending it with new functionality...


You can highlight a part of a text with the follow search code:

<script type="text/javascript">
    $(document).ready(function() {
        $("textarea").highlightTextarea({
              words: ["first word","an other word"]
        });
    });
</script>

Find more about highlighting in a textarea on Highlight text into a textarea