Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically fire ondblclick event in javascript?

I am trying the following simple code (in html, using js on IE8):

<input type="image" src="pic.jpg" id="aa" ondblclick="alert('aa');"/>
<script>
document.getElementById('aa').dblclick(); 
</script>

and I get an error that: object doesn't support this property or method (regarding the script part). And I don't get the alert.

Whereas when I dblclick on the image, I get the alert message. So I wish to know how to programmatically fire the dblclick event (without actually double clicking the image).

The same works just fine with onclick (instead of on dblclick). I also tried it on button, input text. Same error .

like image 301
user965297 Avatar asked Jan 18 '23 15:01

user965297


2 Answers

The property name is ondblclick but you're attempting to call dblclick. You need to call ondblclick.

<script>
  document.getElementById('aa').ondblclick(); 
</script>

Fiddle: http://jsfiddle.net/frwpY/

like image 73
JaredPar Avatar answered Jan 31 '23 02:01

JaredPar


try this:

<input type="image" src="pic.jpg" id="aa" ondblclick="alert('aa');"/>
<script>
document.getElementById('aa').ondblclick(); 
</script>

http://jsfiddle.net/dnUZY/1/

like image 36
Ilia Choly Avatar answered Jan 31 '23 00:01

Ilia Choly