How do I write a jQuery selector that will find elements that have string1 anywhere in its ID, and also string2 anywhere in its ID?
views:
22answers:
3
+3
A:
you mean this? attribute contains selector.
Description: Selects elements that have the specified attribute with a value containing the a given substring.
example,
HTML
<input id="man-news" />
<input id="milkman" />
<input id="letterman2" />
<input id="newmilk" />
jQuery
$("input[id*='man']").val("has man in it!");
$("input[id*='man'][id*='letter']").val("has man and letter in it!");
result: fiddle
Reigel
2010-10-08 07:45:14
@Reigel - That's what I'm currently using, but I'm not sure how to use it to match two seperate strings?
ben
2010-10-08 07:47:03
you mean [this](http://fiddle.jshell.net/XbzCH/)?
Reigel
2010-10-08 07:49:15
+1
A:
You can chain together the contains selector
$("span[id*='first'][id*='second']") // selector for any span with "first" and "second" anywhere in the id
Working example --> http://jsfiddle.net/mtgNE/
Jamiec
2010-10-08 07:49:07
+1
A:
$('div[id*=foo][id*=blah]');
would look for foo
and blah
at all available divs.
Example: http://www.jsfiddle.net/XuKND/
jAndy
2010-10-08 07:52:23