Search code examples
jqueryprototypejscss-selectors

Prototype: How to filter result set, like jQuery?


jQuery


allows something like:

var divs = jQuery('div');
jQuery('a', divs);


Prototype


docs say:

$$('#navbar a', '#sidebar a');
// -> all links within the elements of ID "navbar" or "sidebar"

Which I took to mean that it is performing the same thing as this in jQuery: jQuery('#navbar a, $sidebar a');



So I guess the question is what should the marked line be:

var divs = $$('div');
var inner_spans = $$('span', divs); // * marked line

Solution

  • The select function as Diodeus listed, is what I think I was after.

    var divs  = $$('div');
    var spans = [];
    divs.each(function(div){
       spans.push(div.select('span'));
    });
    

    Really, the only bit I cared about was the div.select('span'), pushing them into an array wasn't really the goal here :)