Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70434

How to change button background color when clicked (but not other buttons)?

$
0
0

@Wrybread wrote:

I have a grid of buttons, and I’m trying to change the background color of the most recently clicked button, but have the other buttons not have that background. Ideally I’d like to add a style to the most recently clicked button, and remove that style from all other buttons.

Currently my buttons are defined like this:

<ion-col size="6" 
  class="mainButton" 
  (click)="DoStuff(1, true)">
  <img src="assets/images/icon-aurora.png" height=70>
</ion-col>

I’m still wrapping my head around Ionic so please forgive anything silly that I’m doing. Here’s the function call (currently not working):

DoStuff(data: string, swapBg: boolean = false) {

    if (swapBg) {
      this.style.backgroundColor = '#345465';
    }

    return;

Any tips to change the background color of just the button that was clicked? Ideally without having to make a separate variable for each of the buttons, since I have a lot of them?

Is there some way to pass the ID of the clicked button, using “this”?

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 70434

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>