You have to do something like this:

$(this).attr("checked") ? $(this).val() : 0

This will return the value if it's checked, or 0 if it's not.

$(this).val() is just reaching into the dom and getting the attribute "value" of the element, whether or not it's checked.

-- Josh

----- Original Message ----- From: "Skilip" <[EMAIL PROTECTED]>
To: "jQuery (English)" <jquery-en@googlegroups.com>
Sent: Tuesday, May 15, 2007 2:00 PM
Subject: [jQuery] Getting a checkbox value



Hi, how do I get the value of a checkbox? If i use this code I get for
both checked and unchecked 1 as a result.

$('#edit-use-background-image').change(function() {
alert($(this).val());
});


Reply via email to