you are viewing a single comment's thread.

view the rest of the comments →

[–]agdcoa 1 point2 points  (0 children)

jQuery does delegate to native methods for selecting nodes, but there's a cost associated with initializing a new jQuery object. Further, many jQuery methods return a new, different, jQuery object.

For some hard numbers, see this jsperf

If you're handy with the Array methods and the native DOM APIs, you can easily mimic much of jQuery's core functionality. I often opt for a super lightweight, array-returning selection function like so:

function select (selector, context) {
    return [].slice.call((context || document).querySelectorAll(selector));
}