I have a set of 3 divs all sharing the same class.
<div id="qq1" class="cl">sentence</div>
<div id="qq2" class="cl">sentence</div>
<div id="qq3" class="cl">sentence</div>
I am interested in finding out how to properly write code that will trigger a mouse event for these 3 divs with one function, targeting the 'cl' class and returning the appropriate ID for adjusting CSS properties. For example:
<script>
$('.cl').on('mouseenter', function() {
var currentId = $(this).attr('id');
$('#' + currentId).css("background-color", "#99cc33");
$('#' + currentId).css("color", "white");
});
$('.cl').on('mouseleave', function() {
var currentId = $(this).attr('id');
$('#' + currentId).css("background-color", "white");
$('#' + currentId).css("color", "#404040");
});
</script>
However, there seems to be an issue because it is not functioning as expected.