How do I implement this JavaScript block with jQuery?
JavaScript
x
5
1
var x = document.getElementById("name");
2
if (x.style.backgroundColor == "black"){
3
//do this
4
}
5
I get stuck at this point:
JavaScript
1
4
1
if ($("#name").css() == ???){
2
//Do this
3
});
4
Advertisement
Answer
This should work!
JavaScript
1
6
1
var color = $("#name").css("background-color");
2
3
if(color == "black"){
4
//do this
5
}
6
OR
if you would like it in one line:
JavaScript
1
4
1
if($("#name").css("background-color") == "black"){
2
//do this
3
}
4