the second parameter of toggleClass() should be allowed to be non-boolean
|Reported by:||waltertross||Owned by:|
|Keywords:||Cc:||kswedberg, paulirish, SlexAxton|
var modif = $('#x').hasClass('xModif') OR $('#y').find('.yModif').length;
(please replace the OR with a double vertical bar, which the tracking system refuses to display)
This example doesn't work currently, unless one replaces length with length > 0, because modif will be true if hasClass() returns true, but it will be an integer otherwise, and toggleClass() currently only uses the second parameter if it is of boolean type.
This example is particularly tricky, because many people tend to think that the OR condition always produces a boolean, and because it will not fail in all cases.
The suggested enhancement is to ignore the second parameter of toggleClass() only if it is undefined, converting it to boolean otherwise.
Alternatively, a big warning in the documentation is suggested.
Change History (6)
comment:4 Changed 6 years ago by SlexAxton
- Cc kswedberg paulirish SlexAxton added
- Milestone changed from 1.4.3 to 1.5
- Priority set to low
- Status changed from new to open
comment:5 Changed 6 years ago by john
- Keywords needsdocs added
- Resolution set to wontfix
- Status changed from open to closed