Issue
Hello I've tried several things to give my submit button the onsubmit attribute. But I can't figure out, how to set onsubmit. Maybe you have an idea.
let btn = document.createElement('input');
btn.value = "Delete";
btn.name = "deleteButton";
btn.type = "submit";
btn.onsubmit="deleteCell();
let btn = document.createElement('input');
btn.value = "Delete";
btn.name = "deleteButton";
btn.type = "button";
btn.addEventListener('submit', deleteCell())
Solution
The "submit" event is for a form, not an input. You can use the "click" event on the input through:
const deleteCell = () => {
console.log("hello World!")
};
let btn = document.createElement('input');
btn.value = "Delete";
btn.name = "deleteButton";
btn.type = "button";
btn.addEventListener('click', deleteCell);
Answered By - Peshraw Hasan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.