Make A Selected/Clicked Button Active In JavaScript

Raja Tamil
4 min readAug 29, 2022

Learn how to make a selected or clicked button active in JavaScript without Loop.

You can either add a CSS class or add one or more CSS properties directly to a selected button to be active.

Add A Background Colour To A Selected Button

When you want to add some CSS style to a selected/clicked button in JavaScript to make it active,

For Loop will most likely be the first choice in our minds.

But, you do not need to use loop at all.

Let’s see how to do it in action.

Create HTML Button Elements

Here is a simple div tag with an id wrapper.

It has five HTML button elements in it.

Nothing fancy.

<div id="wrapper">
<button>1</button>
<button>2</button>
<button>3</button>
<button>4</button>
<button>5</button>
</div>

--

--

Raja Tamil

👇click the link and get 80% OFF on the premium web development courses (HTML5, CSS3, JavaScript ES6, Vue JS 3 & Firebase 10 https://softauthor.com