javascript - Creating and trigger dynamic ID -


i can't figure out... trying create list. in every li there same users.

i want create unique div id each user possible click , link specific click functions...

here got:

$(document).ready(function(){      var columnsarray = [];      for(var = 0; < 3; i++){          var userarray = [];          for(var j = 0; j < 2; j++){              userarray.push("<div id='userholder-"+j+"-"+i+"'>userid "+j+"</div>");              $(function(){                 $("#userholder-"+j+"-"+i+"").click(function() {                     alert("it works!");                 });             });         }          columnsarray.push($("#thelist").append("<li><div class='info'></div>"+userarray+"</li>"));      }  }); 

when using j , in "userholder" won't work... if discard j , works perfect... impossible trying do???

jsfiddle example: http://jsfiddle.net/jmansa/stulj/

hoping , in advance :-)

it isn't right way.

add class every div, , data-id when call click function:

the jquery code:

$(document).ready(function(){      var columnsarray = [];      for(var = 0; < 3; i++){          var userarray = [];          for(var j = 0; j < 2; j++){              userarray.push("<div id='userholder-"+j+"-"+i+"' class='press' data-id='"+j+"-"+i+"'>userid "+j+"</div>");          }          columnsarray.push($("#thelist").append("<li><div class='info'></div>"+userarray+"</li>"));      }     $('.press').click(function(){         alert($(this).attr("data-id"));     })  }); 

the fidle updated: -> http://jsfiddle.net/stulj/1/


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -