0

I have worked in filter option. Here more than one input fields are there. Like one select, input text, button click. All are under one class named "filter-option". When any one of these modified I have to alert the value inside a jQuery.

I have tried below code but not working.

$("body").on('DOMSubtreeModified', "filter-option", function() {
    alert('changed');
});
Khurram Ishaque
  • 778
  • 1
  • 9
  • 26
kowsalya v
  • 31
  • 5

3 Answers3

1

If you want the event to be fired whenever something is changed within the element then you could use the change, keyup, blur events.

$("body").on('change keyup blur', "filter-option", function() {
   alert('changed');
});

see also: Detecting input change in jQuery?

Jeni
  • 320
  • 2
  • 12
0

You can use Keyup function.

Keyup

<script type="text/javascript">
 $(document).ready(function () {
   $('#SelectorName').keyup(function () { alert('text changed'); });
 });
</script>

OR using keypress

keypress

<input type="text">

Jquery

$(document).ready(function(){
  $("input").keypress(function(){
  alert("clicked");
  });
});

OR using blur().

blur

blur gives you the change event only when you click on something else post entering the value in the input field.

function yourFunction() {
  alert("clicked");
}
<input type="text" id="fname" onblur="yourFunction()">
Manjuboyz
  • 6,978
  • 3
  • 21
  • 43
0

I think the best way is to store a flag in data-attribute of your form.

$(document).on("change", "#your_form_id :input", function () {
$("#your_form_id").data("changed", true);
alert("changed");
});

It will invoke change event of all the input fields inside the form tag.