I have some code that displays a series of buttons on a website.
<input id="btnDay1" class="daybtn" type="button" value="Day 1" onclick="displayGraphicxxx (Day1)"</input>
<input id="btnDay2" class="daybtn" type="button" value="Day 2" onclick="displayGraphicxxx (Day2)"</input>
I need to have the page update the buttons when a user selects a different option to:
<input id="btnDay1" class="daybtn" type="button" value="Day 1" onclick="displayGraphicyyy (Day1)"</input>
<input id="btnDay2" class="daybtn" type="button" value="Day 2" onclick="displayGraphicyyy (Day2)"</input>
I understand that .innerHTML will not work in this case, and when I tried using .value instead, nothing was changed. How can I change the onclick section programmatically?
2
Answers
I suggest you delegate to the closest common container (calendar div?) and use an event listener
Also your HTML was invalid
Here you are a way you could do that. It is simple for your case.
.setAttribute
gets two props: