1

IE10 shows cross button in the text box which clear the text boxcontent. I want to capture that event so that I can mark text box red. Any idea?

αƞjiβ
  • 3,056
  • 14
  • 58
  • 95
  • 1
    I doubt *that* "button press" can be captured (as it is not a separate button but rather part of the browsers interface for a textbox), but the underlying/resulting event (maybe a "value change") could probably be captured. – user2864740 Sep 12 '14 at 20:47
  • I already have .on('keyup mouseup', '.myClass', function() {}); binding but its not catching this event. – αƞjiβ Sep 12 '14 at 20:50
  • Neither keyup nor mouseup are the underlying [change event](http://api.jquery.com/change/) (or [input event](http://stackoverflow.com/questions/17384218/jquery-input-event)). What happens if the user's browser auto-completes the field? Same thing: only binding to the key/mouse events *misses* what actually happens. – user2864740 Sep 12 '14 at 21:10
  • can I have .on(keyup mouseup propertychange',..)? I tried this an didn't capture click on cross button event. – αƞjiβ Sep 12 '14 at 21:15

1 Answers1

2

How about this:

$("textarea").on('input propertychange', function() {
    if ($(this).val() == "") {
        $(this).css("background-color", "#f00");
    }
});

See this fiddle: http://jsfiddle.net/sLzhgezf/1/

Edit: You should actually use .on instead of .bind. I've updated the answer and the fiddle.

Schlaus
  • 18,144
  • 10
  • 36
  • 64