homepage Welcome to WebmasterWorld Guest from 50.19.33.5
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe and Support WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Javascript Loop if
BlackRaven




msg:3344899
 10:38 pm on May 20, 2007 (gmt 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;
}

 

Drag_Racer




msg:3344959
 12:40 am on May 21, 2007 (gmt 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;
}

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved