Hey folks, I was wondering whether there were plans to support Element.closest()
in jsdom?
No plans to support the non-existent Element.closest. Element.prototype.closest, however, we might try to support in the future. A pull request would be the best way to get work on that moving forward.
@domenic Is Element.prototype.closest
different from what I linked above? Can't find a corresponding MDN article other than that one.
I think it's just MDN being confusing. But if you check out any browser (or spec), Element.closest === undefined
, whereas Element.prototype.closest
is a function.
Oh, okay. I'm sure you didn't mean it, but your initial response made me feel like a noob for not knowing the difference, and I hope that's not representative of this community. I'll try to dive into the jsdom code to see whether I understand enough to contribute.
Unfortunately, I don't have the time at the moment to dig into and understand the jsdom code base, but the following snippet is all that's required.
window.Element.prototype.closest = function (selector) {
var el = this;
while (el) {
if (el.matches(selector)) {
return el;
}
el = el.parentElement;
}
};
Perhaps someone that's already working on the project can slip that in at the appropriate place.
Since that one was closed out now there is https://github.com/tmpvar/jsdom/pull/1951
It still isn't in jsdom, right?
This was fixed by the merging of https://github.com/jsdom/jsdom/pull/1951 in v11.12.0 🎉
Most helpful comment
Unfortunately, I don't have the time at the moment to dig into and understand the jsdom code base, but the following snippet is all that's required.
Perhaps someone that's already working on the project can slip that in at the appropriate place.