- This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
Viewing 5 posts - 1 through 5 (of 5 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Please, explain part of the script
Hi guys.
Here is source http://codepen.io/Kuzyo/pen/bCdut I can’t undestand this part
function highlight(node) {
if (highlightedCell) {
highlightedCell.style.backgroundColor = '';
}
highlightedCell = node;
node.style.backgroundColor = 'red';
}
Please, explain somebody, what does mean **highlightedCell** ? Author didn’t get it by Id or in another way and what this **if (highlightedCell)** verify?
Thanks in advance.
What Mottie said. Keep track which cell is highlighted so you can easily clear the highlight.
sorry for noobie question but which background this code clear
if (highlightedCell) {
highlightedCell.style.backgroundColor = '';
}
everyone elements that has background??? :)))
No, that variable `highlightedCell` is a reference to the current element that has the highlight background.
function highlight(node) {
// checks if there is an element currently highlighted (with the background color)
if (highlightedCell) {
// if so, remove the background color from that element
highlightedCell.style.backgroundColor = ”;
}
// highlightedCell is now a reference to the new highlighted element
highlightedCell = node;
// give new highlighted element the background color
node.style.backgroundColor = ‘red’;
}
Thanks for detailed explanation. I understood everything.