JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/dot-luv/jquery-ui.css">
<textarea></textarea>
JavaScript
$.fn.tabToggle = function( fn ) {
var args = arguments, i = 1;
while ( i < args.length ) {
jQuery.proxy( fn, args[ i++ ] );
}
return this.keydown( jQuery.proxy( fn, function( event ) {
if((event.keyCode || event.which) !== 9) return;
var lastToggle = ( jQuery.data( this, "lastTabToggle" + fn.guid ) || 0 ) % i;
jQuery.data( this, "lastTabToggle" + fn.guid, lastToggle + 1 );
event.preventDefault();
return args[ lastToggle ].apply( this, arguments ) || false;
}));
};
$("textarea").tabToggle(function() {
$(this).css('backgroundColor', 'white');
}, function() {
$(this).css('backgroundColor', 'blue');
}, function() {
$(this).css('backgroundColor', 'green');
}, function() {
$(this).css('backgroundColor', 'red');
}).focus();