The "name" attribute isn't the same as the "id" attribute (though in
IE it "kind of" is).

On a side note, XHTML and HTML differ in how you make something "checked":

HTML:
  <input type="checkbox" checked>

XHTML:
  <input type="checkbox" checked="checked">

If you want to select by "name" you'll need to do this:

  $("input[name=tog_0]")

Or you could add an "id" to the checkboc it if you want:

  <input class="show_tog" type="checkbox" checked="checked" id="tog_0"
name="tog_0"/>

Then your $("#tog_0").attr('checked') will work.

On a side note, jQuery (or $) always return a jQuery object. To check
to see if that "object" (it acts a bit like an array) actually
contains anything check it's length. That is:

  if ( $('#something').length ) {
    // an object with id="something" exists on the page
  }

Karl Rudd

On Thu, Feb 5, 2009 at 12:02 PM, Chris <chris.b...@gmail.com> wrote:
>
> This is incredibly basic, but I'm missing something. I have this html:
>
> <input class="show_tog" type="checkbox" checked=""  name="tog_0"/>
>
> I want to find the toggle and get the value of checked. I have tried
> the following, but nothing works:
>
> alert ($("#tog_0").attr("checked"));
> alert ($("#tog_0").checked);
>
> both give me undefined.
>
> $("#tog_0") is giving me an object.
>
> What am I missing?
>
> --
> Chris
>

Reply via email to