This is part of my code. I just wanted to know why document.getElementById("myName").onclick
works and document.getElementByClassName("myClass").onclick
does not work in the following onclick arrow function example?
Does onclick
arrow function take document selector as ID by default or support only Id?
What if i want to implement onclick to class in this case?
//myName.onclick = async () => { //even this representation works
document.getElementById("myName").onclick = async () => {
try {
//some code here which call some async function (not related so not writing here)
alert('clicked.');
} catch(e) {
log(e);
}
};
<html>
<button id="myName" class="myClass"><strong>Click me</strong></button>
</html>