0

Is it possible to use a regex in jQuery's bind method for custom events. Something like...

$(selector).bind(myRegex, function(){})

flag
1  
Can you provide an example regex so we can understand what you're trying to achieve? Something like... capture all mouse events? – eyelidlessness Jul 29 '09 at 15:49

1 Answer

0

If you're trying to use a regex to select only certain DOM elements, you can use the .filter() method to pass in a function that would then perform regex logic to filter out the elements that don't match.

$(selector).filter(function (index) {
                  return /myregex/.test($(this).attr("id"));
                })

Otherwise it's not too clear what you're trying to do...

link|flag
It's not the selector, it's the name of the custom event that I want to use a regex for. For example, if I have two custom events, 'CustomerAdd', and 'CustomerDelete' that can be announced, I'd like to be able to listen for 'Customer*'. – Hal Helms Jul 29 '09 at 16:10

Your Answer

get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.