Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Is there a functional difference between $('.selector', myContext) and myContext.find('.selector')?

Tags:

jquery

I feel like $('.selector', myContext) and myContext.find('.selector') are two identical ways to get the same information. Is there a practical reason when you would use one over the other? Speed perhaps?

like image 519
Jason Avatar asked Jun 23 '10 23:06

Jason


1 Answers

$('.selector', myContext) and $(myContext).find('.selector') are completely equivalent:

From the jQuery 1.4.2 source (core.js):

//...

// HANDLE: $(expr, context)
// (which is just equivalent to: $(context).find(expr)
} else {
    return jQuery( context ).find( selector );
}

//...
like image 158
Christian C. Salvadó Avatar answered Oct 05 '22 20:10

Christian C. Salvadó