sudoku - I am trying to get simple jquery code to iterate -


i trying assign text sudoku puzzle (made table) using jquery , can indvidual cell using following code:

$('#popsud').click(function(){ $('#1').text('1'); }); 

but want apply entire 81 cell table , trying following code no success:

function popsud(sudname) {   (var = 0; i<81; i++) {     $('#i').text(sudname[i-1]);   } } $('#popsud').click(function(){      popsud(easy);   }); 

i managed errors disappear using dev tools hitting wall. using 81 number array code.

this part not work:

 $('#i').text(sudname[i-1]); 

jquery literally looking element id "i", not number looking for.

try code:

 $('#' + i).text(sudname[i-1]); 

note i starts counting 0, element ids have start 0 well. looks have couple off-by-one errors in code now.

besides that, recommend reconsider names give functions , variables. right now, might know popsud means, if have touch code again in 6 months? not much. why don't call populatesudoku? considering fact pretty modern development environments have code completion feature, additional legibility comes free!


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -