You could use:

$('#test')[0].checked

Your original attempt to use $('#test').checked didn't work because checked
is a property of the DOM element, not the jQuery object. By using [0] you
get the first (and in this case, only) DOM element in the jQuery object's
array of elements.

$('#test') is pretty fast, but of course document.getElementById is the
fastest if that's a consideration.

-Mike

> From: George
> 
> Thanks,
> But I think that
> if (document.getElementById('test').checked ) {} would be 
> better...performance wise and readability is better
> 
> Is there problem with this approach?
> 
> PS: Is there shorter syntaxes for document.getElementById('test')?
> 
> Thanks
> George.
> 
> 
> On Nov 12, 1:25 pm, ripple <[EMAIL PROTECTED]> wrote:
> > try:
> >  
> > if ($("#test").is(":checked")) {}
> >  
> >  
> >
> > --- On Wed, 11/12/08, George <[EMAIL PROTECTED]> wrote:
> >
> > From: George <[EMAIL PROTECTED]>
> > Subject: [jQuery] working with checkboxes
> > To: "jQuery (English)" <jquery-en@googlegroups.com>
> > Date: Wednesday, November 12, 2008, 1:11 PM
> >
> > I have a checkbox
> > <input type="checkbox" id=test>
> >
> > the $('#test').checked always returns undefined. No matter 
> if checkbox 
> > checked or not...
> > Is it how it's supposed to be?
> >
> > I thought that $('#test') will return me the object wrapped 
> so i have 
> > original methods/properties as well as new one that came 
> from JQuery.
> > Am i mistaken?
> >
> > Thanks
> > George.
> 

Reply via email to