Aymn Khallel
Aymn Khallel

Reputation: 29

Change value of tag attibute?

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

Answers (2)

wirey00
wirey00

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;
});​

http://jsfiddle.net/rMnx3/

Upvotes: 2

Fenton
Fenton

Reputation: 250842

You should use removeAttr to remove the read only attribute:

$('.hidden').removeAttr('readonly');

Upvotes: 1

Related Questions