i want to click a radio element automatically with js. Element selection is perfect because when i try to change it with innerHTML, it changes but click() does not work.
Code:
document.addEventListener("DOMContentLoaded", function(){
document.querySelector(".jet-radio-list__label").innerHTML = "Changed!"
document.querySelector(".jet-radio-list__label").click()
}
Tried Alternatives like:
document.querySelectorAll('input[type="radio"]').checked = true;
2
Answers
You cannot click a radio button, but you can set the element to "checked". And then you can dispatch an event if that is needed.
Maybe something like the following?: