Search code examples
jquerycssclassclick

Changing parent Div background color on active tab


I am trying to figure out how to change the parent div container background color when clicking a tab. I want to have it so that when a tab is active it adds a class to the parent div. Each active tab would add different bg color to the parent.

Link to the example

This is what I would like to do.

enter image description here


Solution

  • I tried it in your console, check this

    var colors = ["red", "black", "yellow"];
    jQuery(document).ready(function() {
      jQuery(".vc_tta-tabs-list > li").on("click", function() { 
        jQuery(".grve-section").css("background", colors[jQuery(this).index()])
      })
    })
    

    $ is not assigned in your code, that's why I changed to jQuery here