# How can I change the button background color on click in ionic 3 app

**URL:** <https://forum.ionicframework.com/t/how-can-i-change-the-button-background-color-on-click-in-ionic-3-app/120182>\
**Category:** ionic-v3\
**Created:** [February 1, 2018, 7:15pm UTC](https://forum.ionicframework.com/t/how-can-i-change-the-button-background-color-on-click-in-ionic-3-app/120182 "2018-02-01T19:15:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shivaniunomaha](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@shivaniunomaha](https://forum.ionicframework.com/u/shivaniunomaha)\
**Post date:** [February 1, 2018, 7:15pm UTC](https://forum.ionicframework.com/t/how-can-i-change-the-button-background-color-on-click-in-ionic-3-app/120182/1 "2018-02-01T19:15:55Z")

</div>

I have a quiz app where when I try to change the color of the selected button on the click, the color of all the button changes. I am trying to access the index of the button but i am sure how to implement it.  
can someone please help

```auto
<div class="options" *ngFor="let option of q.options; let i = index;">
        <button (click)="selectAnswer(option, i)" block ion-button [color]="ionicColor">{{ option.name }}</button>
      </div>

```

My function looks like this

```auto
selectAnswer (selectedOption, index) {
    this.selectedAnswer = selectedOption;
    console.log(this.allQuestions);
    this.ionicColor="dark";
  }

```

---

<div class="post-metadata">

**Author:** ![jamesharvey](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jamesharvey/32/116080_2.png) [@jamesharvey](https://forum.ionicframework.com/u/jamesharvey)\
**Post date:** [February 1, 2018, 7:19pm UTC](https://forum.ionicframework.com/t/how-can-i-change-the-button-background-color-on-click-in-ionic-3-app/120182/2 "2018-02-01T19:19:29Z")

</div>

Try to use ngClass or ngStyle. Please look them up. They allow you to change CSS3 style on click.

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:52pm UTC](https://forum.ionicframework.com/t/how-can-i-change-the-button-background-color-on-click-in-ionic-3-app/120182/3 "2021-07-19T21:52:36Z")

</div>

Closed on July 19, 2021, 9:52pm UTC


