0

so I have the following structure:

 <div class="num1">1,2</div>  
 <div class="num11">2,2</div>  

 <div class="num2">5,4</div>  
 <div class="num21">3,2</div>  

 etc...

I want a jQuery selector that will select only num1 and num2, numX where X being only one number. Currently I have a selector:

alert($("div[class^='num']").max());  

which of course returns all of the num's, so I'm wondering if there is some sort of way to handle this easily. Btw, if someone is wondering what the .max() is, it is from jQuery calculation plugin

Nikola
  • 14,888
  • 21
  • 101
  • 165

1 Answers1

3

Here you have it

$("div[class^='num']").filter(function(){
   return /^num\d$/.test($(this).attr("class"));
})

It uses a regular expression to select elements with appropiate classnames.

Hope it helps

Edgar Villegas Alvarado
  • 18,204
  • 2
  • 42
  • 61
  • This helps, though now I'm lost cause I can't seem to access the return values properly. Am new to jQ :( Here's what I've been trying: http://jsfiddle.net/Hitman666/sQLu7/2/ – Nikola Apr 28 '11 at 08:12
  • I saw the jsfiddle, you are writing `innerHtml` instead of `innerHTML`. The problem is solved with that. Alternatively, you can use jquery's `t.html()` instead of `t[0].innerHTML` – Edgar Villegas Alvarado Apr 28 '11 at 08:41