Hacker News new | ask | show | jobs
by kivikakk 4685 days ago
I saw the quoted text in the original page and stopped reading right there; who on earth wants to use a query library where you have no idea whether what's returned is an array of elements or just an element?
2 comments

Why would you have no idea? If you're querying by id, you have one, if you're querying by anything else, assume you have more. Once you assume you have more, you use each() to operate on all or only() to narrow the list. Those functions handle the abstraction for you, just like a jQuery wrapper does.
Contrived, but if I write:

    var allMyPageHeaders = HTML.find(".header");
    allMyPageHeaders[0].textContent = 'This is my main header';
... and there's only one element on the page with the class ".header", my code is now broken.

Unless I'm missing something, and an "HTML'ified node" acts as an array in the single case.

Yep. You certainly can misuse it. You are supposed to do: allMyPageHeaders.only(0), because that works on a node or node list in HTML.js.
People whose only use case is an extremely simple demo example in a blog posting?