function influence on already running function JavaScript -
so have function show me random number images css class. problem when running application twice , sec application alter images on first application, while random numbers dont show in sec application. thought because didn't have local variable, same problem or without global vars. utilize iframes, there must away work js ?
i created jsfiddle show problem, press run button twice , play dices you'll see problem. http://jsfiddle.net/dymond/gul9u/
and function creates classes.
function dicesides_func(nr){ // go dice-window-wrapper 1 time again // set in seporate functon var elementtoadddice=" dice-window-wrapper ", obj=this, // using here that's why it's called wiht dice,i=0,total=0; // dice in dice window // dicesides_func.call set right context if(nr) { while((" "+obj.classname+" ").indexof(elementtoadddice)==-1){ obj=obj.parentnode; } obj=obj.getelementsbytagname("ul")[2]; var dicessides = createelementwithclass('li',nr); obj.appendchild(dicessides); // calculate total (can in seporate function) dice = obj.getelementsbytagname("li"); } else { dice = document.getelementsbyclassname("dice"); } for(i=0;i<dice.length;i++){ total=total+getnumberforclass(dice[i].classname); } //alert(total); var wrapper = document.getelementsbyclassname("dice-toolbar-counter-wrapper")[0]; while (wrapper.haschildnodes()) { wrapper.removechild(wrapper.lastchild); } var ttl = total.tostring(); var arr = []; (var = 0;i<ttl.length;i++) { var digit = ttl[i]; var newelem = createelementwithclass('li',"side-" + ttl[i]); //alert(dice_toolbar_counter_wrapper_li) wrapper.appendchild(newelem); } }
javascript
No comments:
Post a Comment