A possible error in jQuery 1.6 is $ (...). Attr ("checked") does not work

I have two radio buttons in my form, and until I started using jQuery 1.6, the following code worked fine:

<input type="radio" id="radio1" name="test"/>
<input type="radio" id="radio2" name="test"/>
<input type="button" onclick="testcheck()" value="Test"/>
<script>
function testcheck()
{
    if (jQuery("#radio1").attr("checked"))
        alert("first button checked");
    else if (jQuery("#radio2").attr("checked"))
        alert("second button checked");
    else
        alert("none checked")      
}
</script>

As soon as I start using jQuery 1.6, it always shows "none checked" because it is jQuery(radiobutton).attr("checked")always empty.

Take a look at jsfiddle and change the jQuery version between 1.5.2 and 1.6 to see what I mean.

+3
source share
6 answers

Take a look at this question: .prop () vs .attr ()

Try this instead of code:

function testcheck()
{
    if (jQuery("#radio1").prop("checked"))
        alert("first button checked");
    else if (jQuery("#radio2").prop("checked"))
        alert("second button checked");
    else
        alert("none checked")      
}

Also in the latest jQuery 1.6.1 they fixed some of the 1.6 issuesattr

+8
source

, :

http://christierney.com/2011/05/06/understanding-jquery-1-6s-dom-attribute-and-properties/

, @Neal, 1.6.1.

RC:

1.5.2 1.6.1 - .prop() .attr(), jQuery 1.6 , . , 1.6.1. 1.5.2 1.6.1, .

, 1.6.1 ...

EDIT - 5/16/11

, ... ....

http://ejohn.org/blog/jquery-16-and-attr/

+3

. , , ( ?);

$('#thingy').is(':checked');

-.

, !

+3
source

I can not explain the changes between versions, but there is a special selector that searches for a checkbox - http://api.jquery.com/checked-selector/

0
source

You can hack it like this: jQuery("input[name='test']:checked")

Demonstration:

http://jsfiddle.net/8Eqpu/15/

0
source

.attr()and .data()changed a lot in jQuery 1.6.

This is better explained in this article:

Upgrading to jQuery 1.6: issues you may encounter

Hope this helps. Greetings

0
source

All Articles