Skip to content
Advertisement

Add single unique class on button at a time through foor loop

I am trying to add each unique class (given in array) on each button in the accordion.I have written the jquery code but there is some issue with the code.Currently it is adding all of those array classes on the buttons.I just want it to add only a single class at a time.Please highlight the issue in the code. Thanks

EDIT :

In my current scenerio there will be more than four buttons so i want a generic solution which can add the classes on all buttons and it should only add single classs at a time.

JQUERY CODE :

JavaScript
JavaScript

Advertisement

Answer

Consider Example #1.

JavaScript
JavaScript

This iterates over the buttons and will repeatedly assign a class.

Consider Example #2

JavaScript
JavaScript

This example iterates the the Array and assigns the class to buttons that match the Index.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement