Using javascript, how do I get the background color of a table cell when I click on it?

前端 未结 2 777
独厮守ぢ
独厮守ぢ 2021-01-13 10:18

I want to have an alert pop up that shows me the background of a table cell whenever i click on it. I just can\'t seem to find or figure out how to grab the background colo

2条回答
  •  难免孤独
    2021-01-13 10:58

    You can do it easily by Jquery css() function

    jQuery(document).ready(function(){
        $(this).click(function () {
              var color = $(this).css("background-color");
              alert(color);
         });
     });
    

    For more detail have a look at this example

提交回复
热议问题