I have a list of divs with IDs which are just incrementing numeric values. I want to select a subset of those divs with IDs between say 7 and 12, like this:

$('.myDivs[ID between 7,12]').doSomething();

Anyone know how to do this?

I can't find anything in the jQuery docs and I have Googled the heck out of this and haven't managed to find a solution yet.


select the divs whose class contain "myDivs", do an each() and within the function check the numeric suffix of the class

<!DOCTYPE html>
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
			var id=($(this).attr('class')).match(/(\d+)$/)[0];
			if( 7 <= id && id <=12)
				doSomething( id, this.className );
	function doSomething(id, cls){
		alert( 'class="' + cls + '" with numeric id=' + id);
	<div class="myDivs6">6</div>
	<div class="myDivs7">7</div>
	<div class="myDivs8">8</div>
	<div class="myDivs9">9</div>
	<div class="myDivs10">10</div>
	<div class="myDivs11">11</div>
	<div class="myDivs12">12</div>
	<div class="myDivs13">13</div>


Apologies for the tardy response, a last minute decision to take a vacation dragged me away from my desk for a while.

Thanks for the solution Hielo, I modified it very slightly to suit my app and it seems to work great.

Cheers, Paulo!