I am trying to run some code when a Material Design Button component is clicked. Nothing seems to be working... can you help? I have tried the following:
- using an onclick when the button is selected, but this doesn't appear to trigger
- Using Jquery to detect the click - but again this doesn't appear to work.
How do we get buttons to trigger functions( surprisingly this is not listed in the documentation!)
<!-- Adding button to add new items-->
<button class="mdc-fab mdc-fab--extended" id="addItem" onClick="addItem">
<div class="mdc-fab__ripple"></div>
<span class="material-icons mdc-fab__icon">add</span>
<span class="mdc-fab__label">New Task</span>
</button>
<!-- End Button -->
Had the same issue.
In the end I used jquery to add an event listener on all items with a specific class.
Now clicking the button works as expected and calls a function called
orderPizzawith the event as parameter !I think that the classic
onClickattribute doesn't work because the click doesn't really occur on the button itself but rather on the autogenerated<span>inside it.