HTML DOM Event Object

Event Object

Events are actions that can be detected by JavaScript, and the event object gives information about the event that has occurred.

Sometimes we want to execute a JavaScript when an event occurs, such as when a user clicks a button.

Events are normally used in combination with functions, and the function will not be executed before the event occurs!


Event Attributes

Below is the event attributes that can be inserted into different HTML elements to define event actions.

IE: Internet Explorer, F: Firefox, O: Opera, W3C: W3C Standard.

AttributeThe event occurs when...IEFOW3C
onblurAn element loses focus319Yes
onchangeThe content of a field changes319Yes
onclickMouse clicks an object319Yes
ondblclickMouse double-clicks an object419Yes
onerrorAn error occurs when loading a document or an image419Yes
onfocusAn element gets focus319Yes
onkeydownA keyboard key is pressed31NoYes
onkeypressA keyboard key is pressed or held down319Yes
onkeyupA keyboard key is released319Yes
onloadA page or image is finished loading319Yes
onmousedownA mouse button is pressed419Yes
onmousemoveThe mouse is moved319Yes
onmouseoutThe mouse is moved off an element419Yes
onmouseoverThe mouse is moved over an element319Yes
onmouseupA mouse button is released419Yes
onresizeA window or frame is resized419Yes
onselectText is selected319Yes
onunloadThe user exits the page319Yes

Mouse / Keyboard Attributes

PropertyDescriptionIEFOW3C
altKeyReturns whether or not the "ALT" key was pressed when an event was triggered619Yes
buttonReturns which mouse button was clicked when an event was triggered619Yes
clientXReturns the horizontal coordinate of the mouse pointer when an event was triggered619Yes
clientYReturns the vertical coordinate of the mouse pointer when an event was triggered619Yes
ctrlKeyReturns whether or not the "CTRL" key was pressed when an event was triggered619Yes
metaKeyReturns whether or not the "meta" key was pressed when an event was triggered619Yes
relatedTargetReturns the element related to the element that triggered the eventNo19Yes
screenXReturns the horizontal coordinate of the mouse pointer when an event was triggered619Yes
screenYReturns the vertical coordinate of the mouse pointer when an event was triggered619Yes
shiftKeyReturns whether or not the "SHIFT" key was pressed when an event was triggered619Yes

Other Event Attributes

PropertyDescriptionIEFOW3C
bubblesReturns a Boolean value that indicates whether or not an event is a bubbling eventNo19Yes
cancelableReturns a Boolean value that indicates whether or not an event can have its default action preventedNo19Yes
currentTargetReturns the element whose event listeners triggered the eventNo19Yes
eventPhaseReturns which phase of the event flow is currently being evaluated   Yes
targetReturns the element that triggered the eventNo19Yes
timeStampReturns the time stamp, in milliseconds, from the epoch (system start or event trigger)No19Yes
typeReturns the name of the event619Yes
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值