Bringing filter support to live method

Bringing filter support to live method

One of my live methods was not working. So I started looking into the code without realizing that live does not support filter method.

Anyway I patched the code to make live support filter method. I am learning both JavaScript and jQuery and hence I am submitting it a bit hesitantly .

Here is my commit



Logic is simple. I am converting following selctor 

  1.  "#container a.filter(.top).filter(.first)"

to 

  1.  ['#container a', '.top', '.first']

using this regex

  1. matches = text.match(/^[^.]*|\.[^.)]*(?=\))/g);


I have not written any tests but if I am headed in the right direction then lemme know and I write write tests.

I tested my changes with following selectors.


  1. $('#container a').filter('.top').live('click', function(e){
  2.    log( $(this).text() + ' clicked1');
  3.    e.preventDefault();
  4.  });
  5.  $('#container a').filter('.top').live('click', function(e){
  6.    log( $(this).text() + ' clicked2');
  7.    e.preventDefault();
  8.  });
  9.  $('#container a').filter('.top').filter('.first').live('click', function(e){
  10.    log( $(this).text() + ' first clicked');
  11.    e.preventDefault();
  12.  });
  13.  $('#container a').filter('.bottom').live('click', function(e){
  14.    log( $(this).text() + ' bottom clicked');
  15.    e.preventDefault();
  16.  });