I have this function toggles the disabled attribute form a input field:
$('.someElement').click(function(){ if (someCondition) { console.log($target.prev('input')) // gives out the right object $target.toggleClass('open').prev('input').attr('disabled', 'disabled'); }else{ $target.toggleClass('open').prev('input').removeAttr('disabled'); //this works } })
the removeAttr
works fine but when i need to add the disabled again it does just nothing. My console.log is triggered (and giving me back the right input field) so I'm sure that my if statement works. But when I inspect the DOM with firebug in firefox, the disabled attribute does not appear.
can someone help me?
PS: please don't focus on the function or the if statement itself, works fine its just that attr that does not work for disabled...
edit: its an input type="hidden" is it possible that disabled does not work on hidden fields?
Thank you all for your contribution! I found the problem:
ITS A FIREBUG BUG !!!
My code works. I have asked the PHP Dev to change the input types hidden in to input type text. The disabled feature works. But the firebug console does not update this status!
you can test out this firebug bug by your self here http://jsbin.com/uneti3/3#. Thx to aSeptik for the example page.
update: 2. June 2012: Firebug in FF11 still has this bug.
UPDATED
DEMO: http://jsbin.com/uneti3/3
your code is wrong, it should be something like this:
$(bla).click(function() { var disable = $target.toggleClass('open').hasClass('open'); $target.prev().prop("disabled", disable); });
you are using the toggleClass function in wrong way
- http://api.jquery.com/toggleClass/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With