Reputation: 1067
i built a big table,and i want to iterate through some classes name on it to use a jquery effect(slideToggle),but when i tried to make a loop via For,nothing occur
html:
<tr>
<td dir="ltr"><a href="">array_push()</a></td>
<td>اضافة عنصر او أكثر لنهاية المصفوفة</td>
<td>530</td>
<td class="example2">12.5</td></td>
<td>12.5</td>
</tr>
<thead>
<tr>
<th colspan="5" rowspan="3" class="slide2" >
<pre class="prettyprint lang-php ">
$a=array("Dog","Cat");
array_push($a,"Horse","Bird");
print_r($a);
</pre>
</th>
</tr>
</thead>
i want iterate through class name (example,slide) to take a number like example1,example2................
jquery:
$(document).ready(function(){
for (var i=1;i<=120;i++){
$(".example[i]").click(function(){
$(".slide[i]").slideToggle(500);
})
}
})
Upvotes: 0
Views: 96
Reputation: 3376
I think you are not appending the index to the class. Look at the below code:
$(document).ready(function(){
for (var i=1;i<=120;i++){
$(".example" + i).click(function(){
$(".slide" + i).slideToggle(500);
})
}
});
Upvotes: 1