Change History

I think findFirst() is more appropriate then findOne() for several reasons: 1) It is more similar to the .first() method and the :first filter. 2) it removes any doubt in case of not simple selectors. Consider ".boo, .foo". We expect the ".foo" element if it precedes the ".boo" one, becouse it is how querySelector() works.

So, I suggest three two additions:

jQuery.findFirst(), that behaves like jQuery.find("...")[0] || null

jQuery.fn.findFirst()...

jQuery.first(), that returns jQuery( jQuery.findFirst("...") )

Note how those additions would play nicely with the existent API. For example:

$(".foo").find(".boo:first")or$(".foo").findFirst(".boo")

$(".boo").first()or$.first(".boo")

EDIT: Rethinking, I come with the conclusion that jQuery.first() would introduce confusion to the API, since .first() is for "filtering" and not for "searching"...

After some consideration and re-reading the forum post, I dont think this makes sense. jQuery's API expects jQuery objects, querySelector is a node, not a list of nodes - so it wouldn't work with the current API anyway... Unless we shove it into a jQuery object, then we're back to good ol' jQuery(selector)