I have some code like the following:
<html>
<body>
<div id="product_descriptioncontent">
<input type="text" id="a" />
<textarea id="b" />
</div>
</body>
<html>
That means, my div contains either inputs, text areas or images. But my question is how to detect the changes when any children value changed in a div?
The
onchangeevent only fires when the element loses focus, that is, when itblurs with a differentvaluethan when it gainedfocus.I’m not aware of any native listener that would provide such functionality in real time, but you could try maneuvering jQuery’s
.data()method to store the current value and check against it in a standard keyboard event, such askeyup:JSFiddle
Note that you may also remap the
keyupto multiple events for extra checks:As well as simply calling
$('#element').keyup()will trigger theonfunction for that element, if you ever need to call it without the user inputting anything. =]Note that the
.on()jQuery method is only supported in jQuery 1.7+, for older versions you should use.live().