简体   繁体   中英

jQuery addClass() method

I am trying to highlight a table row with a specific item ID (in first column) by updating its CSS class, but it is not working:

.inactive {
  background-color: "red";
}

My code calls the following JavaScript function whenever a specific event happens:

function highlight_item(item_id){
  var tableRow = $("#itemsTable tr td:first-child").filter(function() {
    return $(this).text() == item_id
  }).parent();
  tableRow.addClass("inactive")
}

Strangely, it works if I replace the addClass() call with

tableRow.css("backgroundColor", "red")

What I am doing wrong here?

Remove the quotes from "red". Use .inactive { background-color: red; } .inactive { 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