I have a heading in my html which is colored red using css. I want to test whether the css is applied to that heading and alert a message if it is applied using jQuery.
Her is my code.
<html>
<head>
<script src="http://code.jquery.com/jquery-1.4.3.min.js" ></script>
<script>
$(document).ready(function() {
$('#validate_btn').click(function() {
$('.style').each(function() {
if($(this).css('color') == 'red') {
alert("css applied");
}
});
});
});
</script>
<style>
.style {
color: red;
}
</style>
</head>
<body>
<h1 class="style">Heading One</h1><br><br>
<div class="myClass">
<span class="cos_validate_button" id="mybtn">
<button id="validate_btn">Check</button>
</span>
</div>
</body>
</html>
$('style')should be$('.style'). Also, when you debug, you may see that the color isn't represented the way you think it is.$(this).css('color')<-- not going to return "red"