In this example, I will illustrate how to access a series of image buttons to change their CSS class in order to reflect the currently selected button.
First, I’ll begin with a series of html buttons which display images using the CSS background property.
Notice I’ve wired each button to call “changeBtnClass()” and passes to it the current button’s ID and number of buttons displayed.
Its first task is to loop through all the buttons to change their CSS class to reflect an “off” state.
Then using the ID passed of the currently selected button, if accesses just that button and changes its CSS class to change it back to an “on” state.