I'm working on a task to highlight columns and rows in a table from the top to the selected cell and from the left to the selected cell.
Currently, I have achieved highlighting both the whole column and row.
Here is an image of the desired outcome: https://i.sstatic.net/jUFMP.png
I looked for similar cases on the internet but could not find any.
$(document).on('click', "td", function(event) {
var table = 'table'
var styleA = {
'-webkit-box-shadow': 'inset 10px 10px 0px 200px rgba(213, 228, 237, 1)',
'-moz-box-shadow': 'inset 10px 10px 0px 200px rgba(213, 228, 237, 1)',
'box-shadow': 'inset 10px 10px 0px 200px rgba(213, 228, 237, 1)'
};
var styleB = {
'-webkit-box-shadow': 'inset 10px 10px 0px 200px rgba(220, 231, 237, 1)',
'-moz-box-shadow': 'inset 10px 10px 0px 200px rgba(220, 231, 237, 1)',
'box-shadow': 'inset 10px 10px 0px 200px rgba(220, 231, 237, 1)',
'outline': ' 3px solid #086aa7'
};
$(table).find("td,tr").removeAttr('style');
$(table).find("td").removeAttr('style');
//$(this).parent('tr').css(styleA);
$(this).parent('tr').find('td').css(styleA);
$('td:eq(' + this.cellIndex + ')', 'tr').css(styleA);
$(this).css(styleB);
});
$(document).mouseup(function(e) {
var container = $("table");
if (!container.is(e.target) && container.has(e.target).length === 0) {
$("table").find("tr,td").removeAttr('style');
$("table").find("td").removeAttr('style');
}
});
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 500px;
margin: 50px 0 0 50px;
}
td,
th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
table td[contentEditable=true] {
box-shadow: inset 0px 0px 0px 200px rgba(186, 210, 225, 0.51);
outline: 3px solid #086AA7;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<table>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Laughing Bacchus </td>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari </td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
</table>