mahesh
mahesh

Reputation: 351

JavaScript change css

var html = '<table style="width: 100%;border:0.5px solid white; border-spacing:0px; nth-child(even) {color:#ffffff;}"><tr style="background-color:#E9EDDB;padding-top:5px;"><td id="serNum" style="font-family:Segoe UI;font-size:16px;color:#000;text-align:center;width:5%;">' + count + '</td><td style="width: 30%; text-align: left;font-family:Segoe UI;font-size:16px;color:#000;height:auto;overflow-x:none;"><span id="taskDesc" style="">' + i.Description + '</span></td><td style="width: 8%;padding-left:5px; text-align: left;font-family:Segoe UI;font-size:16px;color:#000;"><span id="taskPriority">' + i.Priority + '</span></td><td style="width: 8%; text-align: left;font-family:Segoe UI;font-size:16px;color:#000;"><span id="taskType">' + i.Status + '</span></td><td style="width: 15%; text-align: left;font-family:Segoe UI;font-size:16px;color:#000;"><span id="taskDesc">johnsmith- ' + creatdDate + '</span></td><td style="width: 15%; text-align: left;font-family:Segoe UI;font-size:16px;color:#000;"><span style="display:none" id="taskID">' + i.ID + '</span><select id="dropDown" name="dropDown"><option value="default" SELECTED>Select</option><option value="deleteTask" >DeleteTask</option><option value="createRmndr">CreateReminder</option></select></td></tr></table>';
           items.push(html);
           count++;

using this lot of columns will be generated for my project i want to change odd columns color but i am unable to change it can any one tell me how to change background color for odd and even columns. I have tried this css but this property is not working in JavaScript so please tell me how to do this ..

nth-child(odd)
{ 
    background:#ff0000;
}

Upvotes: 0

Views: 128

Answers (3)

icaru12
icaru12

Reputation: 1582

You must specify nth-child of what element, syntax: element:nth-child(n) { style properties }

td:nth-child(odd)
{ 
   background:#ff0000;
}

Upvotes: 0

Samuel Liew
Samuel Liew

Reputation: 79032

You have to use the !important keyword to override the inline styles applied to the table.

nth-child(odd)
{ 
   background:#ff0000 !important;
}

This will have to be placed in a stylesheet, and cannot be used inline.

Upvotes: 2

CaptainCarl
CaptainCarl

Reputation: 3489

td:nth-child(odd) {  
  color: #ccc;
}

From: http://css-tricks.com/how-nth-child-works/

Upvotes: 0

Related Questions