views:

29

answers:

2

Does the Prototype Javascript library have a selector that's equivalent to jQuery's :contains()? If not, what would what be "The Prototype Way" to selector/filter-down a list of elements that contains a particular string.

For example, using the following

$$('#some_div dd a')

I may get back an array of 50 or so links. I only want the links that contain the work 'home'. In jQuery I'd do this

jQuery("#some_div dd a:contains('home')");

Is it possible to do something similar using Prototype? If not, is there an elegant way to filter out the array of 50 elements that gets returned.

+1  A: 

Have you read the article on the Sizzle intergreation.

http://prototypejs.org/2010/4/5/prototype-1-7-rc1-sizzle-layout-dimensions-api-event-delegation-and-more

This should help you.

RobertPitt
+1 for useful information, and that looks pretty sweet. However, if I could control what version of prototype I was using on this project, I'd pick jQuery ;)
Alan Storm
I Would then suggest that you incorperate SizzleJS inside your application as a library and not part of prototype. such things as `$$(Sizzle('#divid:contains(\'hello world\')'))` this is the best i got :)
RobertPitt
Simple (doesn't exclude classnames or tags, but still might be helpful) contain: `$$('#some_div dd a').each(function(s) { if( s.innerHTML.indexOf('home') >= 0 ) { /* do something */ } });`
Dan Heberden
A: 

The best I've been able to find so far no non-Sizzle answers is to filter things out with the findAll method.

$$(selector).findAll(function(e){ return e.innerHTML.indexOf(label) != -1;}) 
Alan Storm