Since you are only checking if the attribute exist, why not just use `attr()`

If the attribute isn't defined, it returns `undefined`.