Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comma separated list of selectors?

Tags:

I'm refactoring some code at the moment and have come across a selector:

jQuery("tr","#ctl00_MainContent_MyUserControl").each(function(i,row) { ... } 

It looks like it's selecting <tr>'s from the user control on the page (ignore the fact that the instance is fully named!) but it's not a syntax I'm familiar with and can't find anything in the documentation. I'd expect it to be written:

$("#ctl00_MainContent_MyUserControl tr").each(function(i,row) { ... } 

Can anyone tell me if there's a difference (subtle or otherwise) that I'm missing here??

like image 389
Dave Avatar asked Nov 11 '11 10:11

Dave


1 Answers

This selector selects all tr elements inside an element with id ctl00_MainContent_MyUserControl. It is exactly the same as your second example.

The second parameter provides a context for the first parameter. There are better use cases for this syntax, for example:

function(el) {     $('tr', el).each(...); } 

Where el is some element on your page. In this case, you can't use the second syntax form.

like image 135
Ronald Wildenberg Avatar answered Sep 27 '22 19:09

Ronald Wildenberg