I would like to create a fixed element that changes color based on the underlying background via jquery but it doesn't work, can you tell me why?
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#content").scroll(function(){
if( $(".sfondo").css('background-color') == 'black' {
$("#fixed").css('background-color', 'grey');
}) else if($(".sfondo").css('background-color') == 'grey' {
$("#fixed").css('background-color', 'black');
});
});
</script>
<style>
#fixed{width:50px; height:50px; background-color: grey; position: fixed; left: 50%; right: 50%; top: 5%;}
#primo{width: 100%; height: 200px; background-color: black;margin-bottom: 100px;margin-top: 200px;}
#secondo{width: 100%; height: 200px; background-color: grey;margin-bottom: 100px;}
#terzo{width: 100%; height: 200px; background-color: black;margin-bottom: 100px;}
#quarto{width: 100%; height: 200px; background-color: grey;margin-bottom: 700px;}
</style>
</head>
<body>
<div id="content">
<div id="fixed"></div>
<p class="sfondo" id="primo"></p>
<p class="sfondo" id="secondo"></p>
<p class="sfondo" id="terzo"></p>
<p class="sfondo" id="quarto"></p>
</div>
</body>
</html>