0

I need to bind an event on all fields with an id starting with "userLinesXXX" Where XXX will be a number (not necessary 3 digits)

this :

$('[id^="userLines"]').change(function() {

Works perfectly, but I need to add the numbers in the regex (to avoid binding on fields wit hid "userLinesAutoEdited"), but I don't know how to do. I tried with [id^="userLines"\d+] and [id^="userLines"[0-9]] but this doesn't work...

Lempkin
  • 1,458
  • 2
  • 26
  • 49

1 Answers1

0

You can use .filter with a function:

$('[id^="userLines"]').filter(function() {
   return !!$(this).attr('id').match(/^userLines[0-9]+$/);
}).change(function() { ... });
jcubic
  • 61,973
  • 54
  • 229
  • 402