Pergunta

Eu tenho esse código em jQuery, que eu quero reimplementar com a biblioteca de protótipo.

// make external links open in popups
// this will apply a window.open() behaviour to all anchor links
// the not() functions filter iteratively filter out http://www.foo.com 
// and http://foo.com so they don't trigger off the pop-ups

jQuery("a[href='http://']").
      not("a[href^='http://www.foo.com']").
      not("a[href^='http://foo.com']").
      addClass('external');

jQuery("a.external").
      not('a[rel="lightbox"]').click( function() {
      window.open( jQuery(this).attr('href') );
      return false;
});

Como você pode iteratively filtrar uma coleção de elementos usando um equivalente ao não () operadores listados aqui em jQuery?

Foi útil?

Solução

A filtragem pode ser feito usando o método como assim rejeitar:

$$('a').reject(function(element) { return element.getAttribute("href").match(/http:\/\/(www.|)foo.com/); }).invoke("addClassName", "external");
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top