jQuery循环

Hit*_*itz 3 jquery

我有几个Div = class ='CCC'.我想使用jQuery将所有这些div放在一个数组中,然后遍历数组.怎么做

Tho*_*ock 7

使用Each()函数:

$(".CCC").each(function(i){
   alert(this.id + " is the " + i + "th div with this class");
 });
Run Code Online (Sandbox Code Playgroud)

http://docs.jquery.com/Each

编辑:

按照要求:

function LoopTroughDivs(selector){
  $(selector).each(function(i){
   alert(this.id + " is the " + i + "th div with this class");
 });
}
Run Code Online (Sandbox Code Playgroud)