我有一张桌子,我知道如何搜索下一个和上一个TD,但如何在下一个和上一个TR?
012
345 <- example, I clicked on 4, it checks 3 and 5, but how to check on 0,1,2 and 6,7,8?
678
Run Code Online (Sandbox Code Playgroud)
$(document).ready(function() {
$("td").click(function() {
var x = $(this).next().css('backgroundColor');
var y = $(this).prev().css('backgroundColor');
if (x == 'rgb(255, 0, 0)' || y == 'rgb(255, 0, 0)') {
return;
} else {
$(this).css('backgroundColor', 'red');
}
});
});
Run Code Online (Sandbox Code Playgroud)