Forums

  • # May 10, 2013 at 10:18 am

    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.

    # May 10, 2013 at 10:29 am

    What Mottie said. Keep track which cell is highlighted so you can easily clear the highlight.

    # May 10, 2013 at 10:51 am

    sorry for noobie question but which background this code clear

    if (highlightedCell) {
    highlightedCell.style.backgroundColor = '';
    }

    everyone elements that has background??? :)))

    # May 10, 2013 at 5:07 pm

    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’;
    }

    # May 11, 2013 at 12:27 pm

    Thanks for detailed explanation. I understood everything.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

icon-anchoricon-closeicon-emailicon-linkicon-logo-staricon-menuicon-nav-guideicon-searchicon-staricon-tag