0

I have this table with parent and children folders. I am trying to make the parent's background highlight yellow when it is selected so that it will be easier to know that it is selected. However for some reason (I did not build this) whenever the menu item is clicked on the page is refreshed so the highlighted background goes away. How can I make the background remain highlighted please even after refresh? Thanks alot.

This is my code:

var elems = document.querySelectorAll('.rows');

var fnClick = function(){
    var ie = document.querySelectorAll('.rows');
    for (var x = 0; x < ie.length; x++) {
        elems[x].classList.remove("bg-color");
    }
    this.classList.add("bg-color");

}

for (var i = 0; i < elems.length; i++){
     elems[i].addEventListener("click", fnClick);
}

2 Answers2

-1

Well I guess you can store this information into the local storage and check when the page loads if this information is there. Hope it will help.

-1

just record what index was selected and after the refresh add the color to the last selected stored index

Aurelius
  • 178
  • 1
  • 1
  • 14