Bug Tracker

Modify

Ticket #10730 (closed bug: invalid)

Opened 19 months ago

Last modified 19 months ago

if checkbox is checked by jQuery, 'checked' attribute won't disappear when unchecking it manually

Reported by: schmidt.ajax@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.6.4
Keywords: Cc:
Blocking: Blocked by:

Description

The following code makes checkbox unable to correctly determine whether checkbox checked or not:

<script src='jquery-1.6.4.min.js'></script>
<script>
$(window).load(function() {
  $('#chk').attr('checked', 'checked');
  $('#test').click(function(e) {
	alert($('#chk').attr('checked'));
  });
});
</script>

<input id='chk' type='checkbox'>BadCheckbox
<button id='test'>Uncheck & press it to see</button>

So, after clicking on checkbox it will be unchecked, but 'checked' attribute will stay on it.

Change History

comment:1 Changed 19 months ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

That is correct behavior. The user's click does not remove the attribute from the HTML. It only changes the property. If you want to know the dynamic state, use .prop("checked") instead.

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.