开发者

jQuery selector that selects class name with only one number following that class name

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 r开发者_StackOverfloweturns 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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜