Overview:

While attempting to replicate a mouse down event with jQuery, I stumbled upon an unusual issue that initially left me stumped. However, I persevered and ultimately found a solution to the problem. In order to assist others who may encounter this same issue, I would like to share my solution with you.

Jquery .mousedown() and .trigger(‘mousedown’) does not trigger the mouse down listener.

I noticed this whilst doing some development and thought i would make a note and publish it in case anyone else hits the same issue

both functions (".mousedown()" and ".trigger('mousedown')") in the below code block do not trigger the mouse down event.

if you need to do this then the lines below work

$('#thebutton').mousedown(function(event) {
  alert('click')
})

setTimeout(function(){ 
    console.log('trying mouse down')
    $('thebutton').mousedown()
    $('thebutton').trigger('mousedown')
  
  	var e1 = document.createEvent("MouseEvents");
	e1.initMouseEvent("mousedown", true, true, window, 1, 0, 0, 0, 0, false, 	false, false, false, 0, null);
	$('#thebutton')[0].dispatchEvent(e1)
}, 3000);