The second parameter passed to jQuery defines the scope or context of the first selector.
It tells jQuery to find all elements with class elem inside the element specified in the second parameter. Elements with a class .elem outside of elem will not be selected.
Given the following HTML:
<div id="included"> <input/> <input/> </div> <div id="excluded"> <input/> <input/> </div>
These selectors produce the following output:
console.log($("input", "#included").length); //2 only those inside included console.log($("input").length); //4 all inputs
Working example: http://jsfiddle.net/LE6eE/
source share