jquery and grabbing td title to tack on new td?
I am trying to get the titles from my td:
function titleObject(table) {
var titleArray=[];
$('tr',table).each(function(i){
var data={};
$('td',this).each(function(j){
data[j]=$(this).attr('title');
})
titleArray.push(data);
});
return titleArray;
}
I am not sure this will work. The next thing is I want to tack the title on to a td:
function objectToTable(objectArray,table){
var body=$('tbody',table);
var color = colorStyleObject(table);
var title = titleObject(table);
body.children().remove();
if(options.zebra){
for(var i=0;i<objectArray.length;i++){
(i%2)?(tr=$('<tr class="'+options.zebraClass+'"></tr>')):(tr=$('<tr></tr>'));
for(var j in objectArray[i]){
tr.append($('<td class="ui-widget-content"></td>').html(objectArray[i][j]));
}
body.append(tr);
}
} else {
for(var i=0;i<objectArray.length;i++){
tr=$('<tr></tr>');
for(var j in objectArray[i]){
开发者_Go百科 tr.append($('<td class="ui-widget-content"></td>').attr(title[i][j]).css('background-color',color[i][j]).html(objectArray[i][j]));
}
//$('.ui-widget-content').css('background-color','green');
body.append(tr);
}
}
}
This does not seem to be working. The page just churns forever. Am I getting the title correctly? Am I not tacking it on to the new td line correctly?
Try changing
var data={};
to
var data=[];
looks like you create data as an object and then try to use it as an array.
精彩评论