Bug Tracker

Opened 6 years ago

Closed 6 years ago

#13716 closed bug (duplicate)

checkbox attr/removeAttr problems

Reported by: calmhawk@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.0
Keywords: Cc:
Blocked by: Blocking:

Description

I believed the bug is involved with the version 1.9.0. Here is a simple example: <html>

<head>

<script src="./jquery-1.9.0.js" type="text/javascript"></script>

</head> <body>

<input id="test" type="button" value="click"> <fieldset>

<input class="test" type="checkbox" value="a"> <input class="test" type="checkbox" value="b"> <input class="test" type="checkbox" value="c"> <input class="test" type="checkbox" value="d"> <input class="test" type="checkbox" value="e">

</fieldset>

</body> <script>

$("#test").click(function(){

$(".test").each(function(){

if($(this).attr('checked'))

$(this).removeAttr('checked');

else

$(this).attr('checked', 'checked');

});

});

</script>

</html>

Here are the steps:

  1. Click the button, all the elements are checked.
  2. Click again, no checked.
  3. Click again, the attribute 'checked' is absolutely added, but the box is not checked.

The versions after 1.8.3 have the problem, but the version 1.8.3 is ok.

Change History (1)

comment:1 Changed 6 years ago by m_gol

Resolution: duplicate
Status: newclosed

Duplicate of #13667.
Use prop(), not attr() for this.

Note: See TracTickets for help on using tickets.