Removed used of hasAttribute, as it fails in IE. Using alternative.