0

I want to select those classes in jquery that starts with e and end with a numerical value.

i am using

$('[class^="e"]').hide();

but it selects even those classes that do not end with a numerical value.

Tal
  • 1,091
  • 12
  • 25
  • You can do it using regex selectors. Please check this out http://stackoverflow.com/questions/190253/jquery-selector-regular-expressions – prashant Sep 09 '15 at 04:47
  • 4
    what if there is another class also for that element... anyway this will be a very inefficient operation... why can't you add another class to all those elements like `e-num` along with `e-` like `div class="e-num e-6"` – Arun P Johny Sep 09 '15 at 04:47
  • possible duplicate of [jQuery select class with a number. e.g. foo1, foo2, foo3, foo4](http://stackoverflow.com/questions/10259213/jquery-select-class-with-a-number-e-g-foo1-foo2-foo3-foo4) – m69's been on strike for years Sep 09 '15 at 04:49

1 Answers1

2

try this:

$("div:regex(class, ^e[0-9]+$)").hide()

This uses the :regex selector by James Padolsey. Get the regex selector here.

Matijs
  • 3,118
  • 2
  • 29
  • 41
Super Hornet
  • 2,839
  • 5
  • 27
  • 55