Solace Solace - 2 years ago 85
jQuery Question

What is the second argument in this jquery select statement?

I have seen it here. What is meant by

in the following statement? What does it imply?

var rows = $('tr', tbl);

Answer Source

The tbl in the above is another dom element. This is passed in as a context (jQuery( selector [, context ] )) for the selector 'tr'.

So essentially this:

$('tr', tbl);

says return me everything that matches the selector 'tr' in the element(s) tbl.


So given

<table id="test">

This returns varying results:

//context is global
$('tr') => first & second

//restrict the context to just the second table 
//by finding it and passing it into the selector
var tbl = $('#test');
$('tr', tbl) => just second
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download