Possible Duplicate:
What is the fastest method for selecting descendant elements in jQuery?
I think both are selecting exactly the same. Are there any benefits concerning speed or usability?
Possible Duplicate:
What is the fastest method for selecting descendant elements in jQuery?
I think both are selecting exactly the same. Are there any benefits concerning speed or usability?
I should have searched better first. I found a good answer in the link below:
What is the fastest method for selecting descendant elements in jQuery?
As far as I can see they should be functionally equivalent, but the first one (#id .class
) should be faster since it's only a single call to jQuery instead of two calls, while the amount of work to be done should be the same otherwise.
They are evaluated in an almost identical manner. jQuery searches for elements from right to left then walks up the DOM tree to see if they match the next selector going left.. So this will be evaluated in an identical fashion.
Actually, I believe they would give you two different results.
The first one would get all elements that have an id of "id" AND have a class named "class"; this should only return a single element as an id is suppose to be unique for the entire document.
The second one would return all elements that have a class of "class" and would also include the element with an id of "id".