NaN
NaN

Reputation: 1306

How do I change the css with JQuery

data-record-key is added to all of my table rows. The value of this attribute increments. When a user adds a row, that row is dynamically added with ajax. I want to change the color of that row but can't figure out how to do that.

This is what that attribute looks like:

data-record-key="31"

$('#test').find('.data-record-key').val('31')
 .css("cssText", "background-color:#"+ data.record.myColor +" !important;");

Upvotes: 0

Views: 58

Answers (2)

Selvakumar Arumugam
Selvakumar Arumugam

Reputation: 79830

Try using attribute equals selector and apply the style,

$('tr[data-record-key=31]').css('backgroundColor', '#' + data.record.myColor); //no need !important

Upvotes: 1

Mike Robinson
Mike Robinson

Reputation: 25159

Use an attribute selector:

$("#test").find('[data-record-key=31]').css("cssText", "background-color:#"+ data.record.myColor +" !important;");

Upvotes: 0

Related Questions