views:

116

answers:

1

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

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

A: 

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...

womp
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*'.