简体   繁体   中英

Add row to table and change its background color

I have an html string that I want to append to a table as a row using jquery, and I also want to change the background colour of this newly added row to red. This is what I've currently got for simply adding the row without the background colour:

$(outputString).appendTo('#billTable tbody').hide().fadeIn(2000);

But when I try using the code below, I get an error saying "Uncaught syntax error, unexpected string":

$(outputString).appendTo('#billTable tbody').css({"background-
color":"red"}).hide().fadeIn(2000);

Any clues on how to add in the background colour?

Hmm that's weird - your code should work as it is. You could try using this instead:

$(outputString).appendTo('#billTable tbody').css('background-color', 'red').hide().fadeIn(2000);

I've replaced

.css({"background-color":"red"})

with

.css('background-color', 'red')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM