Butters
Butters

Reputation: 1057

Javascript onclick and ondblclick in same button

does anybody know an solution for buttons to react on 2 click events for only one button:

<input type="button" value="Click" ondblclick="alert('double')"; onclick="alert('ones')";>

@At my try if I double click on button, it alert only 'ones'; Why it isn't possible to have ondblclick and onclick in the same button?

Upvotes: 0

Views: 3648

Answers (2)

A. Wolff
A. Wolff

Reputation: 74420

<input type="button" value="Click" ondblclick="console.log('double');" onclick="console.log('ones')";>

Magically, it works!

Your problem is you are using alert() which is modal and so makes your ondblclick event impossible to be fired.

Upvotes: 6

Sasidharan
Sasidharan

Reputation: 3740

You an give timeout for click so that alert pops up bit slow..

<input type="button" value="Click" ondblclick="alert('double')"; onclick="setTimeout(function(){alert('ones')},3000);";>

Upvotes: 2

Related Questions