Gosi
Gosi

Reputation: 2003

How to NOT onclick in JQuery?

How do I write the code for a NOT onlick event in JQuery?

I tried to go through the NOT documentation for JQuery and also went through this question, but I was unable to find the answer.

This is what I tried:

$!('.form-submit').click(function() {
    // Do something when the form is NOT clicked.
});

Totally lost and unable to figure out the syntax to say when the submit button is NOT clicked.

Upvotes: 0

Views: 52

Answers (1)

CertainPerformance
CertainPerformance

Reputation: 371233

Initialize a timeout, and inside the click handler, clear the timeout:

const timeoutId = setTimeout(() => {
  console.log('You did not click form-submit within 5 seconds');
}, 5000);

$('.form-submit').click(function() {
  clearTimeout(timeoutId);
});

Upvotes: 3

Related Questions