Controlling Calsses hasclass(),addClass(),removeClass()
function
hasClass(obj, c) {
return new RegExp('(\\s|^)' + class +
'(\\s|$)').test(obj.className);
}
function
addClass(obj, class) {
if (!hasClass(obj, class)) {
obj.className += ' ' + class;
}
}
function
removeClass(obj, class) {
if (hasClass(obj, class)) {
obj.className = obj.className.replace(new
RegExp('(\\s|^)' + class + '(\\s|$)'), ' ').replace(/\s+/g, '
').replace(/^\s|\s$/, '');
}
}
No comments:
Post a Comment