Gadgets, Computers and Nerdy Stuff
Archive for March, 2011
Javascript addClass/removeClass functions
Mar 18th
While looking for compact Javascript addClass and removeClass functions, I stumbled upon http://snipplr.com/view/3561/addclass-removeclass-hasclass/.
This code allows for a few optimizations:
- The ‘match’ method is deprecated, ‘test’ should be used instead.
- The ‘addClass’ function references a non-existing ‘this’ object.
- The ‘removeClass’ function declares a new variable ‘reg’, which is unnecessary.
- The ‘removeClass’ function doesn’t handle multiple More >