Reputation: 145
I have a code that works on 1.8.3 (successfully add SUFFIX after blur or focusout when something is typed), but won't work on 1.9.1 or higher.
<div id="mmm">
<input type=text class="gen"><br>
<input type=text class="gen"><br>
<input type=text class="gen">
</div>
$("#mmm").on('focusout change blur','.gen', function() {
var myvar=$(this);
coreid=this.value;
$.ajax (
{
url: '/echo/html/',
success: function (data,status) {
myvar.empty().attr("value", coreid + "MYSUFFIX" );
}
})
})
Check Fiddle on 1.8.3/ If you change to version 1.9.1 or higher the code stop works (Suffix not added at end when something is typed)
http://jsfiddle.net/6nch5fp2/5/
Upvotes: 0
Views: 171
Reputation: 207881
By reading jQuery Core 1.9 Upgrade Guide you'd see what changed. Important to you is:
jQuery 1.6 introduced the .prop() method for setting or getting properties on nodes and deprecated the use of .attr() to set properties. However, versions up to 1.9 continued to support using .attr() for specific situations.
So change .attr
to .prop
:
$("#mmm").on('focusout change blur', '.gen', function () {
var myvar = $(this);
coreid = this.value;
$.ajax({
url: '/echo/html/',
success: function (data, status) {
myvar.empty().prop("value", coreid + "MYSUFFIX");
}
})
})
You'll also notice that if you include the jQuery Migrate plugin that you can continue to use .attr()
And as Terry noted below, .val() is probably the way to go regardless: myvar.val(coreid + "MYSUFFIX");
Upvotes: 3