Skip to content

Element.has() and a cross-browsable "hasAttribute" #2240

Open
@ibolmo

Description

@ibolmo

(from Lighthouse)

Hi,

The other day I was stuck in one of those moments where doing something simple is strangely complicated (thanks IE <3). I ran into a situation where I must validate if an element property has been set, and I thought "oh, I'll just use my_element.has('someattribute')" and to my surprise there was no such thing.

Since hasAttribute is not available for older versions of IE, I started browsing through the MooTools code and I found something that looks like a possible implementation: https://github.com/mootools/mootools-core/blob/master/Source/Slick/...

Testing for it in IE7 (IE9 in IE7 mode) and IE6 (with Chrome IE Tab extension) it seems to work without problem.

I think the Element "class" could use a has method since the get method could be considered ambiguous for this purpose as it returns
null for when the attribute does not exist and for when it is empty (which IMHO should return an empty string).

Regards,

David


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions