Warning, JavaScript is not enabled in your browser. Please enable JavaScript or else the examples will not work.

What is Unhighlight?

Unhighlight is a JQuery plugin that provides an unhighlight (deselect) event for textarea and input form elements.

The unhighlight event is triggered when text that was highlighted becomes deselected through mouse clicking, typing, or deleting within the input element.

Try It Out

Input

Textarea

Code

//Attach to all input elements
$(“input“)
.unhighlight(function() {
alert(“Unhighlight for input element.”);
});
//Now for all textarea elements
$(“textarea“)
.unhighlight(function() {
alert(“Event came from the textarea.”);
});

Notes

  • Chrome-based browsers and IE will automatically perform a deselection event for a textarea when refocusing on the textarea after losing focus on a textarea that previously had text selected. Supposedly, there is text ‘abc’, highlighted in a textarea. Focus is lost by pressing tab and then the textarea is refocused by pressing shift tab. The unhighlight event will trigger for the above browsers.

  • Text must be completely unhighlighted for the unhighlight event to occur. Partial unhighlighting is not supported. For example, the text ‘123’ is selected in a textarea with the mouse still held down. The mouse moves to change the selection to ‘12’, but the unhighlight event will not trigger.

  • If text was selected in an input or textarea element, focusing away from the element will not trigger the unhighlight event.

  • Requires JQuery >= 1.7 but should be on the >= 1.10.x branch to support older IE.

  • Tested with Opera >= 12.16, Firefox 23, Chrome 29, IE >= 6.