skip elements in each function by conditions
how can I skip some elements in each function of jquery by the next
condition:
var number_of_td = 0;
$('td').each(function() {
if (number_of_td == 0) {
if ($(this).attr('id') == "1") {
//skip the next three elements:
//something like: $(this) = $(this).next().next().next();
}
}
else if (number_of_td == 1) {
if ($(this).attr('id') == "2") {
//skip the next two elements
}
}
else if (number_of_td == 2) {
if ($(this).attr('id') == "3") {
//skip the next element
}
}
else if (number_of_td == 3) {
if ($(this).attr('id') == "4") {
//skip the next element
}
}
else {
number_of_td++;
if (number_of_td == 4) {
number_of_td = 0;
}
}
});
for example:
<td attr="1"></td>
<td attr="6"></td>
<td attr="7"></td>
<td attr="9"></td>
//-------------------
<td attr="2"></td>
<td attr="5"></td>
<td attr="3"></td>
<td attr="6"></td>
//-------------------
<td attr="7"></td>
<td attr="2"></td>
<td attr="8"></td>
<td attr="6"></td>
if one of the 4th conditions exists, skip till the td element with attr=2.
in this example, the first td attribute is 1, so it skips till attr=2 and
not check the other elements (attr=6,7,9).
2 is not equal to 1, 5 is not equal to 2, 3 is equal to 3, so it skips
till attr=7, etc.
I hope you can understand my example.
any help appreciated!
No comments:
Post a Comment