Reputation: 29
I would like to change the value of the readonly
attribute using jQuery but this piece of code does not work :
$('#L1E').live('change',function() {
$('.hidden').attr('readonly','');
return false;
});
Does anyone know why ?
Upvotes: 0
Views: 67
Reputation: 33661
You should be using .on (jQuery 1.7+) delegation instead of .live since .live() has been deprecated. You should also use the .prop (jQuery 1.6+) method to set the readonly property
$('body').on('change','#L1E', function() {
v = $('.hidden').prop('readonly')
if (v) {
$('.hidden').prop('readonly', false);
alert(v);
}
else {
$('.hidden').prop('readonly', true);
alert(v);
}
return false;
});
Upvotes: 2
Reputation: 250842
You should use removeAttr to remove the read only attribute:
$('.hidden').removeAttr('readonly');
Upvotes: 1