$("tbody td").click(function(element){ if($(element.target).hasClass('selected')){ $(element.target).removeClass('selected') }else{ $(element.target).addClass('selected') } }); function callbackdata(){ var displayTopRow = document.getElementById("topTemplate"); var leftTop =""; var rightTop =""; if(displayTopRow !=null){ var topLen = displayTopRow.cells.length; var topRow = displayTopRow.cells; var temp =""; for(var i=0;i