A weird thing with textarea input event?

As textarea is not an input there is allowed input event?

Like

var button = $("#buttonId");
$("#textareaID").on('input',function(e){
  if(e.target.value === ''){
    // Textarea has no value
    button.hide();
  } else {
    // Textarea has a value
    button.show();
  }
});

This normal?

Thanks!

I think you might be looking for .on('keyup') or .on('keypress').

Are you asking why it works? Or are you saying it isn’t working for you? The input event should work.

1 Like

Why is work? But thanks!

It works because it is a valid event on the HTMLTextAreaElement interface, just as it is for <input> and <select> elements.

1 Like

What you said is very interesting.

Can you take a look here?

https://jsfiddle.net/e1ubd4q2/3/

So this case on select element is work like a change event? So if use change event there is will do same? This case what the advantage to use input or change?

Thanks

For the select element there isn’t really much difference. But for text input elements the difference is in when the event is fired.

input event

Note: The input event is fired every time the value of the element changes. This is unlike the change event, which only fires when the value is committed, such as by pressing the enter key, selecting a value from a list of options, and the like.

1 Like