Checkbox with toggle() breaking the checked/unchecked state
can anyone spread some light?
Why this .toggle()
is breaking the checked/unchecked state of a checkbox?
$('#checkbox').toggle(function(){},function(){});
when 开发者_开发百科I think, it's just doing nothing.
crazy demo
this was taken from comments of this answer
toggle()
called with two callbacks adds a click
event on the targeted element. The event will execute the first callback on even clicks; the second one on odd ones.
Also, and this is why it changes the behaviour, according to the manual:
The implementation also calls .preventDefault() on the event, so links will not be followed and buttons will not be clicked if .toggle() has been called on the element.
精彩评论