MJ
asked on
Determine Which Button element is currently selected using JavaScript only!
How would I detect when the FUND LATER or FUND NOW button is selected or changed? I Know I have to use the class name of "active" for the selected button but not sure what else I need to do?
Thanks!
<div class="toggle-fieldView">
<button type="button" data-value="Fund Now" class="">FUND NOW</button>
<button type="button" data-value="Fund Later" class="active">FUND LATER</button>
</div>
This is a single page app so this content is added dynamically.Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you can add additional tests and not just : if(event.target.dataset)
so you can test if :
- the target is a button
- the dataset.value if one of what you're looking for "Fund Now" or "Fund Value"
- tghe innerHTML if one of you're looking for "FUND NOW" or "FUND LATER"
- the parentNode (classes, tag,...)
- and so on
so you can test if :
- the target is a button
- the dataset.value if one of what you're looking for "Fund Now" or "Fund Value"
- tghe innerHTML if one of you're looking for "FUND NOW" or "FUND LATER"
- the parentNode (classes, tag,...)
- and so on
ASKER
Thank you Leakim!
ASKER
What if there are other elements with "data-set" on the page? I don't want them to trigger this.
Thanks!