Using plain JavaScript (not jQuery), Is there any way to check if an element contains a class?
Currently, I\'m doing this:
This is a bit off, but if you have an event that triggers switch, you can do without classes:
You can do
$('body').click( function() {
switch ( this.id.replace(/[0-9]/g, '') ) {
case 'classOne': this.innerHTML = "I have classOne"; break;
case 'classTwo': this.innerHTML = "I have classTwo"; break;
default: this.innerHTML = "";
}
});
.replace(/[0-9]/g, '')
removes digits from id
.
It is a bit hacky, but works for long switches without extra functions or loops