user11553898
user11553898

Reputation:

How to handle a CSS property of clicked object in Ember?

Tell me please, how to handle onclick action by ID. For example, i’ve something in hbs template:

<button id="myButton" {{action "myAction"}} >OK</button>

it has CSS:

button {color: "red";}

How to do two things by onclick action:

1. Set property to clicked object (only to clicked), eg to set CSS colour “green”,
2. Get some property of clicked (eg CSS colour), and console log or alert.

Thanks in advance!

Upvotes: 0

Views: 26

Answers (1)

Igor
Igor

Reputation: 1588

You can connect the action to the "onclick" event of the button like this

<button id="myButton" onclick={{action "myAction"}} >OK</button>

And then the first argument of the action will be the click event, from which you can take the target DOM element.

Check out this example twiddle: https://ember-twiddle.com/1d14560e0e979dbbdddbfee57c84601c?openFiles=templates.application.hbs%2C

Upvotes: 1

Related Questions