The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript if else statement issue Re: if else statement issue

Chris Coyier

var test = document.getElementById('test');
var class = test.className;

if (class == 'thing') {
// yeah buddy
} else {
// nope darling

Remember that classes can be space-separated though, so you’d likely need to split them into an array based on spaces and then loop through that array testing each one.