Reputation: 474
I have the following input element:
<input type="hidden" id="input_2_204_data" name="input_2_204_data" value>
I need to capture an event when it is changed and value is not empty. I have looked over older SO's questions, however nothing seemed to work.
Here is the latest snippet I have come up with, however it does not work either, and there are no errors in console:
jQuery(document).ready(function(){
var $sign = jQuery('[id$=input_2_204_data]');
$sign.on("change", function(){
alert('hey');
});
});
Any help or guidance is much appreciated.
Upvotes: 0
Views: 61
Reputation: 4946
You have to use the correct selector #input_2_203_data
. Using .change()
works just fine.
jQuery(document).ready(function(){
var $sign = jQuery('#input_2_204_data');
$sign.change(function() {
if($sign.val() != '') {
alert( "Handler for .change() called." );
}
});
});
Upvotes: 0
Reputation: 34150
jQuery(document).ready(function(){
var $sign = jQuery('#input_2_204_data');
alert($sign.val())
});
Upvotes: 2
Reputation: 82241
You have wrong selector to target element, You need to use ID selector #
here to target element by id:
var $sign = jQuery('#input_2_204_data');
$sign.on("change", function(){
console.log($(this).val());
});
Upvotes: 0