I'm trying to read the background color set by bootstrap in the alert box.
var qc = $(".alert-primary").css("background-color");
This returns undefined. How should I get its value?
I'm trying to read the background color set by bootstrap in the alert box.
var qc = $(".alert-primary").css("background-color");
This returns undefined. How should I get its value?
Your doing it perfectly right you can also do as follows:-
$(".alert-primary")[0].style.backgroundColor
or
var qc = $(".alert-primary").css("background-color");
I think your not getting $(".alert-primary") object. Please make sure $(".alert-primary") is getting the correct element, which has background-color.
I found the issue, the selection works only after I 've created a DOM element with that class.
This works:
<div class="alert alert-info">hello</div>
<script>
var aa = $(".alert-info").css("background-color");
alert(aa);
</script>
Without the first line, it doesn't work.