Use `hasAttribute()` instead to avoid code duplication