$(document).on('focus', '.mask-date, .mask-phone', function () {
...
}):
For the above statement is there a way to use wildcard, like below. except that one does not work.
$(document).on('focus', '[class^=mask-]', function () {
...
});
$(document).on('focus', '.mask-date, .mask-phone', function () {
...
}):
For the above statement is there a way to use wildcard, like below. except that one does not work.
$(document).on('focus', '[class^=mask-]', function () {
...
});
The problem with your selector is that it's matching against the class
attribute literally. If one of the inputs has
class="foo mask-date"
it won't match, because mask-
is not at the beginning of the attribute as required by the ^=
modifier. You can do better with:
[class*=mask-]
which will match anywhere in the attribute. This could get a false match if you also had something like class="bitmask-blah"
, but that's probably unlikely.