Applying valid/invalid classes to elements