Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger a onmousedown event manually from javascript (not jquery) on a empty td tag

Tags:

javascript

I want to trigger a ommousedown event on a empty td tag using java script but not using jquery. Any suggestions please

like image 844
vinod kumar Avatar asked Dec 13 '13 13:12

vinod kumar


People also ask

How do you trigger Mousedown?

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.

What is Onmousedown event in Javascript?

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.

How do I use Mousedown event?

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.

What is Mousedown tag in HTML?

The mousedown event is fired at an Element when a pointing device button is pressed while the pointer is inside the element.


1 Answers

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?

like image 98
JessieArr Avatar answered Oct 16 '22 11:10

JessieArr