is it possible to search for the a control on a webform, where you just want to match "anything" for part of it ie:
I have various buttons on a page - which take the id format: ID#(id1)#(id2)#(date) - for example:
ID-8258-3103-2011-12-18
ID-8258-3104-2011-12-18
ID-8258-3105-2011-12-18
I want to pass the (id1) and (date) in a querystring, and then have jQuery search for the first control on the page, which matches the (id1) and (date) and any (id2) - so for example, I pass 8252 and 2011-12-18 - so how would I find the first control above, from jQuery?
$("#ID-8252-????????-2011-12-18")
Instead of using the #id
selector, you can combine multiple attribute selectors, which filters the id attribute (one for the beginning of the id, one for the end):
$('[id^="ID-8258"][id$="2011-12-18"]').addClass('found');
To select only the first match, use the :first
selector (not the same as the :first-child
selector!)
$('[id^="ID-8258"][id$="2011-12-18"]:first').addClass('found');
See http://api.jquery.com/category/selectors/ for reference.
Example:
http://jsfiddle.net/wbLZ8/3/
It seems that these selectors can be used even with IE7, if you want to use them in plain CSS.
You'll want to use a filter in your selector, as discussed in jQuery selector regular expressions. (Check nickf's response for an example).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With