Bug Tracker

Modify

Ticket #10278 (closed bug: fixed)

Opened 3 years ago

Last modified 2 years ago

checkboxEl.attr('checked') returns stale value after checkboxEl.click()

Reported by: IgorMinar Owned by: timmywil
Priority: high Milestone: 1.7
Component: attributes Version: 1.6.4rc1
Keywords: Cc:
Blocking: Blocked by:

Description

This worked fine in 1.6.2:  http://jsfiddle.net/IgorMinar/69fpq/1/

but is broken in 1.6.3 and 1.6.4:  http://jsfiddle.net/IgorMinar/69fpq/

Change History

comment:1 Changed 3 years ago by timmywil

#10274 is a duplicate of this ticket.

comment:2 Changed 3 years ago by timmywil

#10271 is a duplicate of this ticket.

comment:3 Changed 3 years ago by timmywil

  • Owner set to timmywil
  • Priority changed from undecided to high
  • Status changed from new to assigned
  • Component changed from unfiled to attributes
  • Milestone changed from None to 1.7

An issue was introduced in the boolHook for non-IE browsers.

comment:4 Changed 3 years ago by IgorMinar

Indeed the issue is in boolHook:

// Hook for boolean attributes
boolHook = {
    get: function( elem, name ) {
        // Align boolean attributes with corresponding properties
        // Fall back to attribute presence where some booleans are not supported
        var attrNode;
        return jQuery.prop( elem, name ) === true || ( attrNode = elem.getAttributeNode( name ) ) && attrNode.nodeValue !== false ?
            name.toLowerCase() :
            undefined;
    },

More specifically the check: attrNode.nodeValue !== false succeeds when it shouldn't because the value is an empty string and not false.

comment:5 Changed 3 years ago by IgorMinar

While #10271 (marked as duplicate of this issue) is caused by an issue in boolHook it is a different issue present in the set method, while this one is in the get method.

comment:6 Changed 3 years ago by timmywil

@IgorMinar: There is fix for this for 1.7 here:  https://github.com/jquery/jquery/commit/2931fa875f7520f87f79c6cff8b1a40d0b4d141a

If there is an issue with set, please provide a test case on  http://jsfiddle.net to help us reproduce it.

comment:7 Changed 3 years ago by timmywil

#10280 is a duplicate of this ticket.

comment:8 Changed 3 years ago by anonymous

I see the milestone is set to 1.7. Is this going to get backported to a 1.6.x release?

comment:9 Changed 3 years ago by timmywil

No, but the recommended way to get/set booleans is to get/set the properties with the .prop() method. This fix will be available in 1.7, but the boolHook may be deprecated and eventually removed.

comment:10 Changed 3 years ago by timmywil

  • Status changed from assigned to closed
  • Resolution set to fixed

Check for property support in the boolHook before falling back to attribute node. Fixes #10278.

Changeset: daeb66504565d3b95dbd6310778def4166044750

comment:11 Changed 3 years ago by dmethvin

#10434 is a duplicate of this ticket.

comment:12 Changed 2 years ago by anonymous

CHECKBOXEL.ATTR('CHECKED')is still return "checked" for checked and "undefined" for unchecked checkbox

comment:13 Changed 2 years ago by anonymous

I am having the same issue:

CHECKBOXEL.ATTR('CHECKED')is still return "checked" for checked and "undefined" for unchecked checkbox

any updates?

comment:14 Changed 2 years ago by timmywil

That is the desired behavior, but I recommend using  http://api.jquery.com/prop to check the checked value.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.