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

Implement Document.getElementsByClassName #24

Closed
codler opened this issue Feb 29, 2020 · 1 comment
Closed

Implement Document.getElementsByClassName #24

codler opened this issue Feb 29, 2020 · 1 comment

Comments

@codler
Copy link
Contributor

codler commented Feb 29, 2020

Can we add Document.getElementsByClassName?

Currently Im doing this workaround to polyfill getElementsByClassName

const patchDoc = doc => {
  doc.getElementsByClassName = search => {
    const results = [];
    const elements = doc.getElementsByTagName('*');
    const pattern = new RegExp(`(^|\\s)${search}(\\s|$)`);
    for (let i = 0; i < elements.length; i++) {
      if (pattern.test(elements[i].getAttribute('class'))) {
        results.push(elements[i]);
      }
    }
    return results;
  };
  return doc;
}

const doc = patchDoc(new DOMParser().parseFromString(html));
@kethinov
Copy link
Member

I'm for it. PR would be welcome.

kethinov added a commit that referenced this issue Mar 2, 2020
Fix #24 Implement Document.getElementsByClassName
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