Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hasAttribute and hasAttributeNS #13

Open
tunnckoCore opened this issue Sep 11, 2017 · 2 comments
Open

Add hasAttribute and hasAttributeNS #13

tunnckoCore opened this issue Sep 11, 2017 · 2 comments

Comments

@tunnckoCore
Copy link

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

@tunnckoCore
Copy link
Author

tunnckoCore commented Sep 11, 2017

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

@developit
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants