Skip to content

Add hasAttribute and hasAttributeNS #13

Open

Description

@tunnckoCore

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

Activity

  1. tunnckoCore commented on Sep 11, 2017

    @tunnckoCore
    Author

    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

  2. developit commented on Jan 22, 2018

    @developit
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions