user2514925 user2514925 - 2 months ago 12
Ajax Question

css Property for jquery ajax success function

I'm working with MVC3, using the following jQuery AJAX call:

function Displaymaingrid () {
var Geo = $('#ddlGeo').val();
var Vertical = $('#ddlVertical').val();
var Month = $('#ddlMonth').val();

if(Vertical == "All")
{
var Flag = 1;
}
else
{
var Flag = 2;
}
$.ajax({
url: "@Url.Action("TRUnutilizedOwnershipChange", "TravelReady")",
datatype: "html",
type: "post",
data: {strGeo:Geo, strVertical:Vertical, intMonth:Month, intFlag:Flag},
error: function(){},
success: function(data){
$('.travTableContent').empty();
var text3 = data.data.lstunutilizedownershipentities;
for( var item in text3)
{
$('<tr />').html(text3[item]).appendTo('.travTableContent');
$('<td />').html(text3[item].CurrentOwnership).appendTo('.travTableContent');
$('<td />').html('<a href="#" onclick="javascript:GetDetail(\'' + text3[item].CurrentOwnership + '\');">' + text3[item].cnt + '</a>').appendTo('.travTableContent');
}
}
});
}


I want to set the CSS property for success function:

$('<tr />').html(text3[item]).appendTo('.travTableContent');


I want to add the following CSS property in the above line:

("tr:odd").css("background-color", "#d0d1e2")


Where do I need to insert this line?

Answer

Add it after the "for" statement.

for( var item in text3){                   
        $('<tr />').html(text3[item]).appendTo('.travTableContent');            
        $('<td />').html(text3[item].CurrentOwnership).appendTo('.travTableContent');
        $('<td />').html('<a href="#" onclick="javascript:GetDetail(\'' + text3[item].CurrentOwnership + '\');">' + text3[item].cnt + '</a>').appendTo('.travTableContent');            
}
$("tr:odd").css("background-color", "#d0d1e2");
Comments