undom icon indicating copy to clipboard operation
undom copied to clipboard

Add hasAttribute and hasAttributeNS

Open tunnckoCore opened this issue 6 years ago • 2 comments

They are pretty small addition, which can easily be implemented.

tunnckoCore avatar Sep 11 '17 14:09 tunnckoCore

It would be just that

  hasAttribute (key) {
    return this.hasAttributeNS(null, key)
  }

  hasAttributeNS (namespaceURI, key) {
    return (
      this.attributes.hasOwnProperty(key) &&
      this.attributes[key].namespaceURI === namespaceURI
    )
  }

if setting attribute is correctly implemented. The interesting thing about this.attribtues is that it's map, where we have both indices and key names. So if we have this html

<div id="foo" bar="qux">hello</div>

then el.attributes[1] will be AttributeNode, but also it can be accessed with el.attributes.bar

tunnckoCore avatar Sep 11 '17 18:09 tunnckoCore

Definitely open to a PR for this! I'm curious how small it could be.

developit avatar Jan 22 '18 21:01 developit