Should hasClass precede removeClass - jQuery -


is necessary check if class exists before use removeclass api on jquery object? eg.

if($(this).hasclass("test"))    $(this).removeclass("test"); 

or

$(this).removeclass("test"); 

if not necessary, why so?

use this:

$(this).removeclass("test"); 

there no need check class existence.

from jquery sources can see removeclass method uses replace method remove substring:

classname = (" " + elem.classname + " ").replace(rclass, " "); (c = 0, cl = classnames.length; c < cl; c++) {     classname = classname.replace(" " + classnames[c] + " ", " "); }​ 

and replace won't remove if matching substring not exist.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -