Home > Software engineering >  Click Listener in Java Script
Click Listener in Java Script

Time:04-24

I'm New in JS World and i have a problem I had a button and i register a listener in this button in JS File and Remove the Listener Once User Clicked this Button the reigister function is onSaveBtnClicked Ex:

function onSaveBtnClicked() {
clickedDiv.append(createWeeklyDiv());
console.log("== Hello From Weekly Button ==");
saveEventBtn.removeEventListener('click', onSaveBtnClicked);}

and i do the same on another file

function onSaveBtnClicked() {
clickedDiv.append(createDailyDiv());
console.log("== Hello From Daily Button ==");
saveEventBtn.removeEventListener('click', onSaveBtnClicked);}

The Problem is when i clicked On Button on Daily View then I clicked it from another view there is two output in the console the first is Hello From Daily Button and the second output is Hello From Weekly Button which mean that The button didn't remove the first Listener Output

CodePudding user response:

Maybe use this to reference the listener function like so:

...
saveEventBtn.removeEventListener('click', this);
...

CodePudding user response:

hi please could you help me in this exercice please

trainSet = [[2, 2, 2, 'a'], [4, 4, 4, 'b'], [6, 6 , 6, 'b'] testInstance = [5, 5, 5] Similarity: Calculate the Euclidian distances between the testInstance and all point of trainSet (Three points) In our case: Three distances between [5, 5, 5] and [2, 2, 2], [4, 4, 4], [6, 6 , 6] Neighbors: Locate k (Choose k=2 points in trainSet) most similar data instances by choosing the points of trainSet with the minimum distances between the testInstance and all point of trainSet In our case: The two points are: [4, 4, 4], [6, 6 , 6] Response: Generate a response from a set of data instances. In our case: The most similar data instances are [4, 4, 4, 'b'], [6, 6 , 6, 'b'], the testInstance will be affected by the letter ‘b’ (method of majority voting)

  • Related