How to check the background-color of an element using jquery

前端 未结 5 911
闹比i
闹比i 2021-01-05 10:42
if($(this).css(\"background-color\")==Crimson) 

is this correct ? .css(\"background-color\",\"white\") will change the color, but I don\'t want t

5条回答
  •  萌比男神i
    2021-01-05 11:31

    Possible answers in JavaScript is like this:

    if(window.getComputedStyle(document.getElementById("notify-9"),null).getPropertyValue("background-color") == "rgb(220, 20, 60)"){
       alert("matched!");
    }
    

    // rgb(220, 20, 60) is equal to Crimson

提交回复
热议问题