Consider the following HTML:
<div id="Kees_1_test">test 1</div>
<div id="Kees_12_test">test 2</div>
<div id="Kees_335_test">test 3</div>
I would like a selector that selects the divs that look like $('div[id=Kees_{any number}_test]'). How can I achieve this?
Note: the ID’s are generated by Asp.Net.
Try this:
That selector selects all elements that have ids that start with
Kees_and end with_test.As lonesomeday suggested, you can use
.filter()to ensure that the middle part contains only numbers. You can combine.filter()with the example above:That should about as good as it gets. Note that I added
^$to the regex, this will return false on id’s such asKees_123_test_fooalso butKees_123_testpasses.