Welcome to WebmasterWorld Guest from 54.144.3.134

Forum Moderators: open

Message Too Old, No Replies

Javascript Loop if

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

Full Member

10+ Year Member

joined:June 16, 2004
posts:232
votes: 0


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)

Full Member

5+ Year Member

joined:Jan 29, 2007
posts:228
votes: 0


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;
}