Lose the () after the .val function because .val() will set the value. Without the braces it will get the value.
Hi ,
I didn’t get the O/P when i used val without braces .
Please find the screen show for reference .
Below is the Script i used
$('.cityName').change(function(){
alert('hi ');
alert('class names ------ '+this.className);
alert('entered value '+$(this).val);
});
==========================================
O/p :- hi
class names ------ form-group mx-name-textBox4 cityName
I got O/P as below for val
function (value) {
var hooks, ret, elem = this[0];
if (!arguments.length) {
if (elem) {
hooks = jQuery.valHooks[elem.nodeName.toLowerCase()] ||
jQuery.valHooks[elem.type];
if (hooks &&
"get" in hooks &&
(ret = hooks.get(elem, "value")) !== undefined) {
return ret;
}
ret = elem.value;
return typeof ret === "string" ? ret.replace(rreturn, "") : ret == null ? "" : ret;
}
return undefined;
}
var isFunction = jQuery.isFunction(value);
return this.each(function (i) {var self = jQuery(this), val;if (this.nodeType !== 1) {return;}if (isFunction) {val = value.call(this, i, self.val());} else {val = value;}if (val == null) {val = "";} else if (typeof val === "number") {val += "";} else if (jQuery.isArray(val)) {val = jQuery.map(val, function (value) {return value == null ? "" : value + "";});}hooks = jQuery.valHooks[this.nodeName.toLowerCase()] || jQuery.valHooks[this.type];if (!hooks || !("set" in hooks) || hooks.set(this, val, "value") === undefined) {this.value = val;}});}