[jQuery] manipulating like normal DOM

[jQuery] manipulating like normal DOM

.attr() is used to get or set a single DOM attribute, AFAIK. For those
attributes that take their name as a value, like disabled, readonly,
etc., you can just do the following:
$('#'+string).attr('disabled', true);
$('#'+string).attr('disabled', false);
To access the underlying DOM object when you have a jQuery object, use
.get(n), where "n" is the index of the element (always zero if you get
by ID).
$('#'+string).get(0).disabled = true;
m.
-----Original Message-----
From: discuss-bounces@jquery.com [mailto:discuss-bounces@jquery.com] On
Behalf Of Andreas Wahlin
Sent: Tuesday, November 21, 2006 11:47 AM
To: discuss@jquery.com
Subject: [jQuery] manipulating like normal DOM
I've just begun using jquery, and wanted to set the disabled attribute
on a input element. I have a string with an id value, and so I thought
$('#'+string).disabled = 'disabled'; would cut it, but it seems I can't
access normal DOM attributes just like that (I have to confess, I've
used lots of prototype where I could do $(string).disabled =
'disabled';) so I changed it to document.getElementById(string).disabled
= 'disabled', and this worked, but it didn't feel good.
Is there another way, am I supposed to use the $.attr perhaps?
like
$('#'+string).attr('disabled', 'disabled');
and is attr the way to get all the attributes of dom element, would seem
so :) this does seem to be the case, just wanted to ask and receive best
practice
Andreas
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/