2

I have a certain situation I want to clarify for myself, and I would be glad if anyone has any experience with this issue and is willing to explain it to me.

I have a textarea that has a change event handler:

textarea.bind('change', function(event){
    // do something
});

Hypothetically, what if I have some sort of a click event handler that catches all user clicks:

$(document).bind('click', function(event){
    event.preventDefault();
});

Will this handler also cancel blur and change events for a textarea if a user clicks out of it with his mouse? And if it will, how can I prevent this from happening?

Update: Thank you for your answers, I can not say that I tried it, but I have a similar situation and I am trying to rule out possibilities why change is not firing on my textarea. In my case there is a change handler that doesn't work if I click on an area in which all click events are prevented by default and replaced with custom behaviour.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Igor Zinov'yev
  • 3,676
  • 1
  • 33
  • 49
  • I have keydown and change events on a text input and if I add preventDefault() in the keydown event, change events never fire. – mikiqex Aug 28 '18 at 10:46

3 Answers3

3

No, it will only prevent the default browser behavior for the 'click' event.

jAndy
  • 231,737
  • 57
  • 305
  • 359
0

No, it won't.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
0

Hypothetically, what if you just tried it? (answer: it won't, as stated just before me)

If you don't want users to be able to leave a inputfield (which sounds like strange user interaction to me), you might be able to just set focus after a blur/change event - perhaps you would need a small timeout to let the event finish first. I would not recommend it, but it's always worth a try.

CharlesLeaf
  • 3,201
  • 19
  • 16