jQuery: The Write Less, Do More JavaScript Library

Selector Syntax, new to jQuery

View: New views
3 Messages — Rating Filter:   Alert me  

Selector Syntax, new to jQuery

by NauticalMac :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Starting to use jQuery having read 'jQuery in Action'.
Came across the following sysntax for sortable tables:
  $('table.sortable').each(function() {
    var $table = $(this);
    $('th', $table).each(function(column) .....

Clearly the $('th', $table).each syntax results in traversing 'th'
elements that are descendants of each of the 'table.sortable'
elements.  I'm missing where this syntax is documented and explained.


Re: Selector Syntax, new to jQuery

by Charlie Tomlinson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

 I've been around jQuery for about 6 months and only learned that syntax  recently. You won't find it documented very many places, perhaps it's an older style that got phased out for more aesthetic chaining. It is in jQuery core and it does work

NauticalMac wrote:
Starting to use jQuery having read 'jQuery in Action'.
Came across the following sysntax for sortable tables:
  $('table.sortable').each(function()	{
    var $table = $(this);
    $('th', $table).each(function(column)	.....

Clearly the $('th', $table).each syntax results in traversing 'th'
elements that are descendants of each of the 'table.sortable'
elements.  I'm missing where this syntax is documented and explained.


  


Re: Selector Syntax, new to jQuery

by NauticalMac :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Answering my own question.
Missed the optional 'context' parameter on the basic jQuery command.
Works as advertised/expected.


On Jul 2, 6:39 am, NauticalMac <cmcnau...@...> wrote:
> Starting to use jQuery having read 'jQuery in Action'.
> Came across the following sysntax for sortable tables:
>   $('table.sortable').each(function()   {
>     var $table = $(this);
>     $('th', $table).each(function(column)       .....
>
> Clearly the $('th', $table).each syntax results in traversing 'th'
> elements that are descendants of each of the 'table.sortable'
> elements.  I'm missing where this syntax is documented and explained.