I have this:
jQuery('td:contains("Yesss")').closest('tr').css('background-color','#ddf8dd')
How do I correctly add z-index:200?
Thank you!
The easiest way is to pass an object to the .css() method, i.e.:
jQuery('td:contains("Yesss")').closest('tr').css({
'background-color': '#ddf8dd',
'z-index': 200
});
Note that the z-index has to be wrapped in single quotes, otherwise JS will interpret the - as a mathematical minus/subtraction operator. Of course, you can always write the keys using camelCase, i.e.:
jQuery('td:contains("Yesss")').closest('tr').css({
backgroundColor: '#ddf8dd',
zIndex: 200
});
If you want to assign the z-index in a separate line, you can do this:
jQuery('td:contains("Yesss")').closest('tr').css('background-color', '#ddf8dd');
jQuery('td:contains("Yesss")').closest('tr').css('z-index, 200);
Not very efficient or pretty though, there's a lot of bloat. You can cache the selector instead:
var $el = jQuery('td:contains("Yesss")').closest('tr');
$el.css('background-color', '#ddf8dd');
// Some lines later
$el.css('z-index', 200);
background-color to background-colourThe object key should be changed to zIndex as should your backgroundColor.. Any dashed names should be camelcased.