Hi, I'm trying to get the hang of jQuery and I had this simple bit of code that refuses to work. Anyone got an idea of why this might not be working?
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("div").live("click", divclicked);
});
function divclicked()
{
if($(this).css("background-color") == "lightblue")
$(this).css("background-color", "red");
}
</script>
<style type="text/css">
div
{
background-color: lightblue;
}
</style>
</head>
<body>
<div id="testdiv">
this is a test
</div>
</body>
</html>
Thanks in advance for any inputs.
Update: The solution below to use "backgroundColor" instead of "background-color" works when the style is inline, not if you use a stylesheet.
I have updated the example to use a stylesheet.