In continuation of my initial query, which has now been resolved, you can find the original question here.
JS:
$(function() {
var scaletext = {
1: 'SA',
2: 'A',
3: 'N',
4: 'Da',
5: 'SDa'
}
$('.scale').hover(function() {
var $this = $(this);
$this.prevAll('.scale').addBack().css('background-color', 'yellow');
$this.siblings('.scale-text').html(scaletext[$this.data('scale')]);
}, function() {
var $this = $(this);
$this.prevAll('.scale').addBack().each(function(){
$(this).css('background-color', getRandomColor());
});
$this.siblings('.scale-text').html("No Rating");
});
});
HTML
<table>
<thead>
<tr>
<td>Overall</td>
<td></td>
<td></td>
</tr>
</thead>
<tbody>
<tr>
<td>Question 1</td>
<td width="300px">
<div class="scale-text">No Rating</div>
<div data-scale="1" class="scale scale-1"></div>
<div data-scale="2" class="scale scale-2"></div>
<div data-scale="3" class="scale scale-3"></div>
<div data-scale="4" class="scale scale-4"></div>
<div data-scale="5" class="scale scale-5"></div>
</td>
<td>Comment</td>
</tr>
<!--Repeat above section for subsequent questions-->
Currently, each div changes to yellow on hover. How can I ensure that each div in the scale displays a different color when hovered over?