Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fire oninput event with jQuery

I have an oninput event on a textarea to check the height and resize it. Now I need to edit the value sometimes. I do this just by editting the val() in jQuery, but that does not trigger the oninput event. Is there any way to trigger the oninput event programatically with jQuery?

like image 725
Deep Frozen Avatar asked Jun 25 '12 12:06

Deep Frozen


People also ask

What is jQuery onInput?

The oninput event occurs when an element gets user input. This event occurs when the value of an <input> or <textarea> element is changed. Tip: This event is similar to the onchange event.

How do you call one event from another event in jQuery?

$('#b1'). on('click', function(){ $('#select_item'). trigger('change'); }); $('#select_item'). on('change', function(){ var jbyr = $(this).

What is the use of .on in jQuery?

The on() is an inbuilt method in jQuery which is used to attach one or more event handlers for the selected elements and child elements in the DOM tree.

What is trigger method in jQuery?

jQuery trigger() Method The trigger() method triggers the specified event and the default behavior of an event (like form submission) for the selected elements. This method is similar to the triggerHandler() method, except that triggerHandler() does not trigger the default behavior of the event.


1 Answers

Use .on('input'). For example:

$('textarea').on('input', function() {    text = $('textarea').val();    $('div').html(text);  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <textarea placeholder="Type something here"></textarea>  <div></div>
like image 51
Paul Chris Jones Avatar answered Oct 25 '22 20:10

Paul Chris Jones