I'm using jQuery hover function to hover over the box-empty
class. On the hover, it replaces the box-empty
to box-full
.
- On hover over a block, how can I hover over all previous blocks too?
- When clicking on the block, how can I add the class
box-full
to all previous blocks?
Edit: Sorry, I forgot to mention that I need to include the block which has been clicked/hover also (not only the previous ones).
Here's my code:
HTML:
<div class="wrap">
<span class="box box-empty"></span>
<span class="box box-empty"></span>
<span class="box box-empty"></span>
<span class="box box-empty"></span>
</div>
jQuery:
$('.box-empty').hover(function () {
$(this).addClass('box-full');
$(this).removeClass('box-empty');
}, function () {
$(this).addClass('box-empty');
$(this).removeClass('box-full');
});