Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery input element unselect text event? [duplicate]

Possible Duplicate:
Unselect what was selected in an input with .select()

Is there a way to detect when a user unselects text in an input element via jQuery?

(Note: I am not asking about detecting "unselection" -- that is, blur -- of the input element itself, but about the text within the element.)

I am doing

$('#input').select(function () {...}

to show a toolbar with formatting options when the user selects text, but I have not been able to figure out how to detect if the user clears the selection.

Any suggestions?

like image 369
Jesse Freeman Avatar asked Oct 03 '12 22:10

Jesse Freeman


1 Answers

Try the blur Event

$('#input').on('blur',function () {
    if( this.value == ''){
         alert('Blur Event - Text box Empty');
         //Your code here
     }
});

This will fire as soon as the Input field loses the focus.. i.e; it was unselected..

like image 94
Sushanth -- Avatar answered Sep 29 '22 03:09

Sushanth --