Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Convert event object to string in JavaScript?

I am trying to get which event is occured ::

function getEvent(){
    alert(window.event);
}

I am getting below event object. I want it in string to compare. if event onclick event then I want to do the action. how can I get it in string? or how can I convert event object to string?

[object MouseEvent]
like image 603
Asmita Avatar asked Oct 17 '12 10:10

Asmita


3 Answers

Use the type property. window.event.type

like image 148
Asad Saeeduddin Avatar answered Sep 21 '22 22:09

Asad Saeeduddin


You'd probably want:

function getEvent(){
    alert(window.event.type);
}

https://developer.mozilla.org/en-US/docs/DOM/event.type

like image 42
dougajmcdonald Avatar answered Sep 22 '22 22:09

dougajmcdonald


you can easily get it by type like this

function getEvent(){
    alert(window.event.type);
}

More info here

http://www.quirksmode.org/js/events_access.html

http://www.quirksmode.org/js/events_properties.html

like image 40
rahul Avatar answered Sep 19 '22 22:09

rahul