b-fuze / deno-dom

Browser DOM & HTML parser in Deno
https://jsr.io/@b-fuze/deno-dom
MIT License
425 stars 47 forks source link

fix getElementsByClassName #86

Closed Hunam6 closed 2 years ago

Hunam6 commented 2 years ago

Fixed getElementsByClassName with multiple classes separated by a space character as argument

import {DOMParser} from "../deno-dom/deno-dom-wasm.ts"

const doc = new DOMParser().parseFromString('<p class="a b c"></p>', 'text/html')!
console.log(doc.getElementsByClassName('a b')[0]!)

Before only this worked

console.log(doc.getElementsByClassName('a')[0]!)

But as described here, the first example should work too.

b-fuze commented 2 years ago

Multiple class names are tested with AND relation, whereas your implementation seems to test them with OR relation 🤔

b-fuze commented 2 years ago

I'd also prefer if you could use for .. of over .forEach

Hunam6 commented 2 years ago

I fixed the issue you mentioned!

In addition I have two suggestions/comments/questions:

b-fuze commented 2 years ago

Formatting can be handled in a later PR maybe... Not in this one. I do need to deno fmt Deno DOM soon...

Hunam6 commented 2 years ago

Thanks for the improvement idea! I had tunnel vision on my implementation :)

b-fuze commented 2 years ago

Alrighty, thanks