getAttribute() may return either null or "" if the attribute is not present. Thats why i added long if condition.
I think i didn't miss to close curly bracket.Anyway let me check again.