简体   繁体   中英

Is there anyway to add hover effect to the table row elements using javascript

I'm using javascript to add rows into my html table and coz of that I can't change style properties using css.

To add backgroud color I used

r = document.getElementById("table").insertRow();
r.style.background="flouralwhite"

But I couldn't find a way to change the background color when I hover on it. Is there a way to do it.

you can use use :-

const tableRow = document.createElement("tr");
// add td in it if you wish 
// add class to this row
tableRow.className = "hoverAble";

now in your css file add the styling -

hoverable:hover {
   background-colour:"flouralwhite";
}

I think this is what you are looking for .

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