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?


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)). ...


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

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


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


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.


hehe ok
but will the the other way will work either?

It may do so. Give it a try.