Welcome to WebmasterWorld Guest from 107.22.87.205

Forum Moderators: open

Message Too Old, No Replies

Javascript Loop if

     
10:38 pm on May 20, 2007 (gmt 0)

10+ Year Member



I have the following loop which works fine however the problem is that the loop becomes stuck if $("voteid"+id[x]) element is not found on the page. Is there a way to check with an if statment that the element $("voteid"+id[x]) does exists, and if so proceed with the loop?
Thanks

for (var x = 0; x<voteids.length; x=x+1)
{
$("voteid"+id[x]).replace("","");
var total= parseInt($("total"+id[x]).innerHTML)+1;
$("total"+id[x]).innerHTML=total;
}

12:40 am on May 21, 2007 (gmt 0)

5+ Year Member



for (var x = 0; x<voteids.length; x=x+1)
{
if (!$("voteid"+id[x])){continue} // this line will skip it if not found
$("voteid"+id[x]).replace("","");
var total= parseInt($("total"+id[x]).innerHTML)+1;
$("total"+id[x]).innerHTML=total;
}
 

Featured Threads

Hot Threads This Week

Hot Threads This Month