Should hasClass precede removeClass – jQuery

Use just this:

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

There is no need to check for class existence.

From jQuery sources we can see that removeClass method uses replace method to remove the substring:

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

And replace won’t remove anything if the matching substring does not exist.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)