I've been trying to create an interactive green circle that switches between red and green when clicked. Despite checking and rechecking my code, it's still not functioning correctly. I must be making a beginner mistake somewhere. Can anyone point out where I'm going wrong?
$("#greenCircle").click(function() {
console.log($("#greenCircle").css("background-color"));
if ($("#greenCircle").css("background-color") == "red") {
$("#greenCircle").css("background-color", "green");
} else {
$("#greenCircle").css("background-color", "red");
}
});
#greenCircle {
background-color: green;
height: 150px;
width: 150px;
border-radius: 50%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="greenCircle"></div>
This jQuery animation is driving me crazy! No matter what I try, it just won't work smoothly. Even switching text editors didn't solve the issue. Below is the code for the animation. Can someone spot why this isn't working as expected?
<!DOCTYPE html>
<html>
<head>
<title>JQuery</title>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="jQuery Practice.css">
</head>
<body>
hello
<div id="circle"></div>
<script type="text/javascript">
$("#circle").click(function(){
$("#circle").animate({Width:"400px"}, 2000);
});
</script>
</body>
#circle{
width: 150px;
height: 150px;
background-color: green;
border-radius: 50%;
}