0

hi all
is it possible to find with jQuery an id that start with something, then a specific string, and then something.
for example
lets say that i have this divs

<div id="first_search_div1"></div>
<div id="second_search_div2"></div>
<div id="third_bla_div3"></div>

i want to find this patern: *search*

the result should the first div and the second but not the third.
is this even possible?
10x

2
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by Airshow
0

ServerMan,

You need to use jQuery attribute filtering, which provides a limited but highly usable regex notation.

$(document).ready(function() {
	$('div[id][id*="search"]'). ...
});

If the search term is variable, then you can build the selector with a bit of string handling, eg.:

$(document).ready(function() {
	var str = "search";
	$('div[id][id*=%s]'.replace('%s',str)). ...
});

Airshow

Edited by Airshow: n/a

0

hi,
first of all thank you for the reply.
i was wondering what is the difference between:

$('div[id][id*="search"]'). ...

and

$('div[id*="search"]'). ...

10x!

0

And I was hoping you wouldn't ask! :$

I found the $('div[id][id*="search"]') pattern in a jQuery API example and it worked when I tested, so I stuck with it.

Maybe someone else knows the finer points of jQuery selectors of this type.

Airshow

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.