Highlighting Text In Textarea – highlight-ta.js

Category: Form , Javascript | February 24, 2017
Author: taylor-vann
Views Total: 5,390 views
Official Page: Go to website
Last Update: February 24, 2017
License: MIT


Highlighting Text In Textarea – highlight-ta.js


highlight-ta.js is a pure JavaScript library that allows to apply different CSS styles on specific characters within your textarea element using RegExp. Also has the ability to dynamically adjust the textarea’s height to fit its content.

How to use it:

Import the highlight-ta’s JavaScript files into the webpage.

<script src="highlight-ta.js"></script>
<script src="highlight-ta-proto.js"></script>

Add the CSS ID to your textarea element and then wrap it into a DIV container as this:

<div id="highlight-div" class="my-class">
  <textarea id="highlight-ta"></textarea> 

Create a regular expression and initialize / instantiate prototype objects:

var re = new RegExp('CSSScript', 'g');
var taHlght = highlightta(document.getElementById('highlight-div'), 
document.getElementById('highlight-ta'), "mark-style", re);

This will wrap the character ‘CSSScript’ in the mark tag with the CSS class of ‘mark-style’. Then you can style the character whatever you like:

.mark-style {

API methods:

// Initialize or reset the textarea with init():
hlghtTa.init(div, ta, re, dclr);
hlghtTa.init(div, ta, re, dclr, false);

// Turn corners off:

// Release testarea from HighlightTa:

// Get the text:

// Get the CSSStyleDeclaration object:

// Set the z-index:
hlghtTa.setZ(2); //use a number
hlghtTa.setZ("2"); //or use a string

// Set the class for mark:

// Set the RegExp with JavaScript RegExp object:

You Might Be Interested In:

Leave a Reply