How to call function on onClick button property?

Button: {mount: 0.5, x: 480, y:270, type: Button, label: 'Button', onclick: handleClick()}

I want to call the function handleClick() when the button is clicked, I have written the function in Button class as below

    alert("random string");

Thank You!

1 Like

Hi Karan, Lightning doesn’t work exactly the same as you may be used to from HTML/DOM based frameworks. You can’t just attach an onClick handler to a template element.

Instead you have to specifically set the focus to a Lightning Component and then handle the user input inside that component.

Check these pages from the docs for more info:


Thanks, michiel, I’ll try that.

1 Like