jquery - Minification of Javascript and increasing performance -
here code html:
<div class="board"> <table id="mastermind_table_one"> <tr id="one"> <td></td> <td></td> <td></td> <td></td> </tr> </table> <table id="mastermind_table_two"> <tr id="two"> <td></td> <td></td> <td></td> <td></td> </tr> </table> <table id="mastermind_table_three"> <tr id="three"> <td></td> <td></td> <td></td> <td></td> </tr> </table> </div>
here code javascript:
$('.next_round').click(function() { var count = 3; var counter = setinterval(timer, 1000); function timer() { count = count - 1; if (count === 0) { $('#mastermind_table_two').each(function() { $(this).find('td').each(function() { $(this).css("background-color", setrandomcolor); }) }) clearinterval(counter); } })
i building game in when "next_round" button clicked, empty tds filled random background color (there's more code, such setrandomcolor function, it's not relevant question).
i have ten mastermind_tables total, , problem lies. repeating code each table. know how can have listed once , move next td when click "next_round"?
i.e. js code above specific mastermind_table_two. how can have dynamic , move next td once previous 1 executed?
updated
my mistake, must have readed question in worng way
try this, bit of hacky might fit needs
$('.next_round').click(function () { $('[id^=mastermind_table_]').each(function () { $(this).addclass("nottreated");//a fake class control }); var counter = setinterval(timer, 1000); function timer() { var currenttable; if ((currenttable = $(".nottreated").first()) == null) { clearinterval(counter); return; } $(currenttable).find('td').each(function () { $(this).css("background-color", setrandomcolor); }); //after treat table, removes fake class $(currenttable).removeclass("nottreated"); } });
Comments
Post a Comment