As with a certain class on the page, change style of another block?

0 like 0 dislike
4 views
When clicking on the menu item receives the class .active and goes to the page where there is left directory. It is necessary that when .cat-parent:nth-child(1).active directory class .list-group changed background, for example purple, but if .cat-parent:nth-child(2).active, blue. Is it possible to do?
5aa4177ccbd3f897946066.png5aa417854f331089426859.png
Here's the menu
ul class="product-categories"> ProductsFood with meaningHousehold chemicalsIonizers AquaspectrBadIdeas

Directory which should change the background
TUPPERWARE Welding equipmentElectrode holders, clampsElectrodesServing Welding equipmentTorches for semi-automaticComponents for burnersWire

There is code but it does not work if there is a transition to the page.
var colorArray = ['blue', 'violet', 'yellow', 'red', 'green', 'grey']; var listGroup = document.getElementById('list-group1'); $('.cat-item').click(function(event) { $('.cat-item').removeClass('active'); $(this).addClass('active'); listGroup.style.background = (colorArray[$(this).index()]); });
by | 4 views

2 Answers

0 like 0 dislike
$(document).ready(function() { $('.cat-item').each(function() { var colorArray = ['blue', 'violet', 'yellow', 'red', 'green', 'grey']; var listGroup = document.getElementById('list-group1'); if ($(this).hasClass('active')) { listGroup.style.background = (colorArray[$(this).index()]); } }); });

Here is the solution, can someone come in handy
by
0 like 0 dislike
Where #list-group1 ?
goes to the page where you have left the directory

On another page(i.e. another address)? Or do you mean that the anchor "dives" to the element with this id ?
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
110,608 questions
257,186 answers
0 comments
32,723 users