Onclick Event Ocurring Without Click Event Actually Happening - Js
Folks I'm a complete novice so apologise upfront for what is going to be a very basic question, I'm sure. I have a javascript file that is linked to a html file which contains a nu
Solution 1:
The solution:
document.getElementById('sortEnrol').onclick = sortByName(arrEnrolments);
is not registering an eventListener but instead executing the sortByName function. You need a closure here as follows:
document.getElementById('sortEnrol').onclick = function () {
sortByName(arrEnrolments);
};
A few comments:
enrolArray variable is created in the init function but never used
pos variable is defined twice in the sortByName function
Post a Comment for "Onclick Event Ocurring Without Click Event Actually Happening - Js"