Check if class already assigned before adding
Just call addClass()
. jQuery will do the check for you. If you check on your own, you are doubling the work, since jQuery will still run the check for you.
A simple check in the console would have told you that calling addClass
multiple times with the same class is safe.
Specifically you can find the check in the source
if ( !~setClass.indexOf( " " + classNames[ c ] + " " ) ) {
setClass += classNames[ c ] + " ";
}