hi all i am declaring id and class when creating table dynamically as below i have bing using many function to make my click event running but all in vein ,pls help me if anyone can?
This is my dynamic table with id and class i have to call css on “td” click and also click event should be fired
var tableid=0;
// display table.......
$('#page').append("<center> <table id='tables' cellspacing='50px' style='margin-top:70px' >");
for(var j=0;j<row;j++){
$('#tables').append("<tr class='row' id='row"+j+"' style='margin-bottom:50px'>");
for(var k=0;k<5;k++){
if(tableid<tablecount-1){
$("#row"+j).append("<td id='"+tableid+"' class='button' width='150' height='150' background='images/green.png' align='center'>"+
"</td>");
tableid++;
}
}//for ends.
$('#tables').append("</tr'>");
}//for ends
$('#page').append("</center> </table>");
i want to fire event individually for all td and on click i want to call function that pass my id as paramenter; i am using id unique for each “td”and the code commented below is the methods i tried to implement/get my click event fired and call my css running but all in vein,
/*Event.observe(window, 'load', function(){
$('#TBL00001').observe('click', test());
});
function test(){
alert("click :)))");
}
$("'#"+tableCode[tableid]+"'").live(function() {
alert("Table"+tableCode[tableid]);
});
$("'#"+tableCode[tableid]+"'").click(function() {
alert("Table"+tableCode[tableid]);
});
$('#TBL00001').on( 'click', 'td', function() {
alert("Table"+tableCode[tableid]);});
*/
now i have also tried .delegate() which works but i cant pass id (unique) for each td all
$('.button').each(function(){
$(this).click(function{
alert("hi");
});
});
$("tr .row > td .button").each(function() {
var $this = $(this);
alert("hi"+$this);
}
/*$("table").delegate($(this),"click",function(){
alert($(this));
printBill(tabid);
});
I´m not sure if I understand your question.
This code will execute on every td click, and the variable id will contain the td´s id.