I want to trigger a ommousedown event on a empty td tag using java script but not using jquery. Any suggestions please
The mousedown event occurs when the left mouse button is pressed down over the selected element. The mousedown() method triggers the mousedown event, or attaches a function to run when a mousedown event occurs. Tip: This method is often used together with the mouseup() method.
The onmousedown event occurs when a user presses a mouse button over an element. Tip: The order of events related to the onmousedown event (for the left/middle mouse button): onmousedown. onmouseup.
To cause a MouseDown event for a form to occur, press the mouse button in a blank area or record selector on the form. To cause a MouseDown event for a form section to occur, press the mouse button in a blank area of the form section.
The mousedown event is fired at an Element when a pointing device button is pressed while the pointer is inside the element.
I threw together a CodePen demo for you:
http://codepen.io/anon/pen/lrAxp
var element = document.getElementById('testButton');
if(document.createEvent)
{
element.dispatchEvent(new Event('mousedown'));
}
else{
// Internet Explorer (I think)
element.fireEvent("onmousedown", event);
}
You can also check out this SO post for more info: How to trigger event in JavaScript?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With