Reputation: 2339
I have an input box that is created in razor using Html.EditorFor.
@Html.EditorFor(model => model.person.Person.FirstName)
I would like to add a change event to this box so that some code will trigger if the value changes.
I have tried this jquery:
$('#person_Person_FirstName').change(function () {
alert($(this).val());
}).change();
But I'm not getting anything.
Does anyone have any ideas?
Upvotes: 1
Views: 2931
Reputation: 1537
Try this code:
$(function() {
$(document).on('change','#person_Person_FirstName', function() {
alert($(this).val());
});
});
Upvotes: 3
Reputation: 12730
If that is the actual id of that rendered element, then doing this should work:
jQuery(function($) {
$('#person_Person_FirstName').change(function () {
console.log( this.value );
}).change();
});
Upvotes: 0