Using regex with jQuery in binding events

Is it possible to use regular expression in jQuery binding method for custom events. Sort of...

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

For example, if I have two custom events, CustomerAdd and CustomerDelete , that can be declared, I would like to be able to listen to Customer* .

+4
source share
1 answer

If you are trying to use a regular expression to select only certain DOM elements, you can use the .filter () method to pass a function that will then execute the regular expression logic to filter out elements that do not match.

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

Otherwise, it’s not very clear what you are trying to do ...

0
source

All Articles