{"id":250,"date":"2025-01-27T13:10:54","date_gmt":"2025-01-27T10:10:54","guid":{"rendered":"https:\/\/planeta21vek.ru\/elina732\/eng\/?p=250"},"modified":"2025-11-20T20:50:39","modified_gmt":"2025-11-20T17:50:39","slug":"complete-list-of-html-javascript-event-handlers-with-examples","status":"publish","type":"post","link":"https:\/\/planeta21vek.ru\/elina732\/eng\/2025\/01\/27\/complete-list-of-html-javascript-event-handlers-with-examples\/","title":{"rendered":"Complete list of HTML\/Javascript event handlers with examples"},"content":{"rendered":"<p style=\"text-align: justify;\">Event handlers should be used in the correct way; it is advisable not to write them directly in tag attributes, but to install event handlers in included files with JavaScript code. If the jQuery library is used, then the name of the handlers must be written without the on prefix.<\/p>\n<p><!--more--><\/p>\n<h2><span style=\"color: #008000;\">click \/ onclick<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 click on an element; occurs when the element is clicked with the left mouse button (on devices with touch screens it occurs when touched).<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/planeta21vek.ru\/elina732\/wp-content\/uploads\/2024\/11\/sobytiya251124.jpg\" \/><\/p>\n<p style=\"text-align: justify;\">Pop-up recording options<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input value=&quot;Press me&quot; onclick=&quot;alert('Click!')&quot; type=&quot;button&quot;&gt;\r\n&lt;a href=&quot;#&quot; onclick=&quot;alert('Example 1 worked'); return false;&quot;&gt;Example 1&lt;\/a&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Sequence of numbers starting from 1<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;script&gt;\r\n  function countRabbits() {\r\n    for(let i=1; i&lt;=3; i++) {\r\n      alert(&quot;Rabbit number &quot; + i);\r\n    }\r\n  }\r\n&lt;\/script&gt;\r\n&lt;input type=&quot;button&quot; onclick=&quot;countRabbits()&quot; value=&quot;Counting rabbits!&quot;&gt;\r\n&lt;input id=&quot;elem&quot; type=&quot;button&quot; value=&quot;Press me!&quot;&gt;\r\n&lt;script&gt;\r\n  elem.onclick = function() {\r\n    alert('Thanks');\r\n  };\r\n&lt;\/script&gt;\r\n&lt;input type=&quot;button&quot; id=&quot;button&quot; value=&quot;Button&quot;&gt;\r\n&lt;script&gt;\r\n  button.onclick = function() {\r\n    alert('Click!');\r\n  };\r\n&lt;\/script&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Displays \u201cPress me\u201d in a pop-up window &#8211; the contents of the button<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;button onclick=&quot;alert(this.innerHTML)&quot;&gt;Press me&lt;\/button&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Multiple popup event handlers<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input id=&quot;elem&quot; type=&quot;button&quot; value=&quot;Press me&quot;\/&gt;\r\n&lt;script&gt;\r\n  function handler1() {\r\n    alert('Thanks!');\r\n  };\r\n  function handler2() {\r\n    alert('Thanks again!');\r\n  }\r\n  elem.onclick = () =&gt; alert(&quot;Hello&quot;);\r\n  elem.addEventListener(&quot;click&quot;, handler1); \/\/ Thanks!\r\n  elem.addEventListener(&quot;click&quot;, handler2); \/\/ Thanks again!\r\n&lt;\/script&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Getting mouse coordinates from an event object<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;button&quot; value=&quot;Press me&quot; id=&quot;elem&quot;&gt;\r\n&lt;script&gt;\r\n  elem.onclick = function(event) {\r\n    \/\/ display event type, element and click coordinates\r\n    alert(event.type + &quot; \u043d\u0430 &quot; + event.currentTarget);\r\n    alert(&quot;Coordinates: &quot; + event.clientX + &quot;:&quot; + event.clientY);\r\n  };\r\n&lt;\/script&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Changing the background of an object<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;button&gt;Change color&lt;\/button&gt;\r\n&lt;script&gt;\r\nconst btn = document.querySelector(&quot;button&quot;);\r\nfunction random(number) {\r\n  return Math.floor(Math.random() * (number + 1));\r\n}\r\nbtn.onclick = function () {\r\n  const rndCol =\r\n    &quot;rgb(&quot; + random(255) + &quot;,&quot; + random(255) + &quot;,&quot; + random(255) + &quot;)&quot;;\r\n  document.body.style.backgroundColor = rndCol;\r\n};\r\n&lt;\/script&gt;\r\n&lt;button onclick=&quot;bgChange()&quot;&gt;Press me&lt;\/button&gt;\r\n&lt;script&gt;\r\nfunction bgChange() {\r\n  const rndCol =\r\n    &quot;rgb(&quot; + random(255) + &quot;,&quot; + random(255) + &quot;,&quot; + random(255) + &quot;)&quot;;\r\n  document.body.style.backgroundColor = rndCol;\r\n}\r\n&lt;\/script&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Changing the background of an object div<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;div id='myDiv'&gt;Color change element&lt;\/div&gt;\r\n&lt;button onclick='changeColor()'&gt;Change color&lt;\/button&gt;\r\n&lt;script&gt;\r\nfunction changeColor() {\r\n  document.getElementById('myDiv').style.backgroundColor = 'red';\r\n}\r\n&lt;\/script&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Change link color<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;script&gt;\r\nfunction ChangeColor(Element) {\r\n\tif (Element.style.color == 'green') Element.style.color = 'red';\r\n\telse Element.style.color = 'green';\r\n\treturn false;\r\n}\r\n&lt;\/script&gt;\r\n&lt;a href=&quot;#&quot; style=&quot;color: green;&quot; onclick=&quot;return ChangeColor(this);&quot;&gt;Change color&lt;\/a&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Form Validation<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;form&gt;\r\n  &lt;div&gt;\r\n    &lt;label for=&quot;fname&quot;&gt;Name: &lt;\/label&gt;\r\n    &lt;input id=&quot;fname&quot; type=&quot;text&quot; \/&gt;\r\n  &lt;\/div&gt;\r\n  &lt;div&gt;\r\n    &lt;label for=&quot;lname&quot;&gt;Last name: &lt;\/label&gt;\r\n    &lt;input id=&quot;lname&quot; type=&quot;text&quot; \/&gt;\r\n  &lt;\/div&gt;\r\n  &lt;div&gt;\r\n    &lt;input id=&quot;submit&quot; type=&quot;submit&quot; \/&gt;\r\n  &lt;\/div&gt;\r\n&lt;\/form&gt;\r\n&lt;p&gt;&lt;\/p&gt;\r\n&lt;script&gt;\r\nvar form = document.querySelector(&quot;form&quot;);\r\nvar fname = document.getElementById(&quot;fname&quot;);\r\nvar lname = document.getElementById(&quot;lname&quot;);\r\nvar submit = document.getElementById(&quot;submit&quot;);\r\nvar para = document.querySelector(&quot;p&quot;);\r\n\r\nform.onsubmit = function (e) {\r\n  if (fname.value === &quot;&quot; || lname.value === &quot;&quot;) {\r\n    e.preventDefault();\r\n    para.textContent = &quot;Both fields must be filled in!&quot;;\r\n  }\r\n};\r\n&lt;\/script&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Intercepting events from CSS in video with the stopPropagation() function, which, when called in an object&#8217;s event handler, causes the handler to be executed, but the event does not bubble up further down the chain<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;button&gt;Display video&lt;\/button&gt;\r\n&lt;div class=&quot;hidden&quot;&gt;\r\n  &lt;video&gt;\r\n    &lt;source src=&quot;rabbit320.mp4&quot; type=&quot;video\/mp4&quot; \/&gt;\r\n    &lt;source src=&quot;rabbit320.webm&quot; type=&quot;video\/webm&quot; \/&gt;\r\n    &lt;p&gt;\r\n      Your browser doesn't support HTML5 video. Here is a\r\n      &lt;a href=&quot;rabbit320.mp4&quot;&gt;link to the video&lt;\/a&gt; instead.\r\n    &lt;\/p&gt;\r\n  &lt;\/video&gt;\r\n&lt;\/div&gt;\r\ndiv {       position: absolute;\r\n        top: 50%;\r\n        transform: translate(-50%,-50%);\r\n        ...      }\r\n.hidden {\r\n   left: -50%;\r\n  }\r\n.showing {\r\n   left: 50%;\r\n  }\r\n&lt;script&gt;\r\nvar videoBox = document.querySelector(&quot;div&quot;);\r\nvar video = document.querySelector(&quot;video&quot;);\r\nvideoBox.onclick = function () {\r\n  videoBox.setAttribute(&quot;class&quot;, &quot;hidden&quot;);\r\n};\r\nvideo.onclick = function () {\r\n  video.play();\r\n};\r\nvideo.onclick = function (e) {\r\n  e.stopPropagation();\r\n  video.play();\r\n};\r\n&lt;\/script&gt;\r\n&lt;p style=&quot;text-align: justify;&quot;&gt;Show and hide text&lt;\/p&gt;\r\n&lt;button onclick='toggleVisibility()'&gt;Show\/Hide&lt;\/button&gt;\r\n&lt;div id='hiddenDiv' style='display:none'&gt;Hide text&lt;\/div&gt;\r\n&lt;script&gt;\r\nfunction toggleVisibility() {\r\n    let element = document.getElementById('hiddenDiv');\r\n    if (element.style.display === 'none') {\r\n        element.style.display = 'block';\r\n    } else {\r\n        element.style.display = 'none';\r\n    }\r\n}\r\n&lt;\/script&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Loading data via AJAX, to load data from the server without reloading the page<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\nfunction fetchData() {\r\n    \/\/ Here's your code for the AJAX request\r\n}\r\n&lt;onclick=&quot;fetchData()&quot;&gt;Download data&lt;\/button&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Changing the link name from On to Off<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;script&gt;\r\n\/\/wait for the page to load completely\r\nwindow.onload = function () {\r\n\r\n    \/\/get the element identifier\r\n    var a = document.getElementById('switch');\r\n    \r\n    \/\/hang an event on it\r\n    a.onclick = function() {\r\n        \/\/we perform some actions\r\n        if (this.innerHTML=='On') this.innerHTML = 'Off';\r\n        else this.innerHTML = 'On';\r\n        \/\/prevent clicking on href link\r\n        return false;\r\n    }\r\n}\r\n&lt;\/script&gt;\r\n&lt;a id=&quot;switch&quot; href=&quot;#&quot;&gt;On&lt;\/a&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onabort<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 interruption of playback. The onabort event occurs when the download of audio or video is interrupted. The onabort event occurs only when the download is aborted, not when an error occurs. Applies to elements audio, embed, img, object, video.<\/p>\n<p style=\"text-align: justify;\">Notification that video loading has been interrupted<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;video id=&quot;myVideo&quot; onabort=&quot;alert('Video load aborted')&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Notification that image loading has been interrupted<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;img id=&quot;myImage&quot; src=&quot;example.jpg&quot; onabort=&quot;imageAborted()&quot;&gt;\r\n&lt;script&gt;\r\n    function imageAborted() {\r\n        alert(&quot;Image load was aborted by the user.&quot;);\r\n    }\r\n&lt;\/script&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Notification that form submission has been interrupted<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;form id=&quot;myForm&quot;&gt;\r\n    &lt;input type=&quot;text&quot; placeholder=&quot;Enter your name&quot;&gt;\r\n    &lt;input type=&quot;submit&quot; value=&quot;Submit&quot;&gt;\r\n&lt;\/form&gt;\r\n&lt;script&gt;\r\n    var form = document.getElementById(&quot;myForm&quot;);\r\n    form.addEventListener(&quot;abort&quot;, formAborted);\r\n\r\n    function formAborted() {\r\n        alert(&quot;Form submission was aborted by the user.&quot;);\r\n    }\r\n&lt;\/script&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onafterprint \u2013 printing finished<\/span><\/h2>\n<p style=\"text-align: justify;\">The onafterprint event occurs when the page begins printing. The onafterprint event occurs when the print dialog is closed. The browser runs onafterprint and onbeforeprint so that notes, explanations and comments can be added to the printing process. Apply to body.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;body onafterprint=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onautocomplete \u2013 form autofill completed<\/span><\/h2>\n<p style=\"text-align: justify;\">An attribute with which the form can be filled out in one click &#8211; the browser will insert the values \u200b\u200binto the appropriate fields.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;form&gt;\r\n  &lt;label for=&quot;name&quot;&gt;Name:&lt;\/label&gt;\r\n  &lt;input type=&quot;text&quot; id=&quot;name&quot; name=&quot;name&quot; autocomplete=&quot;on&quot;&gt;\r\n&lt;\/form&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onautocompleteerror \u2013 error when autofilling form<\/span><\/h2>\n<h2><span style=\"color: #008000;\">onbeforeprint \u2013 preparation for printing<\/span><\/h2>\n<h2><span style=\"color: #008000;\">onbeforeunload &#8211; document uploaded<\/span><\/h2>\n<p style=\"text-align: justify;\">When a user leaves the page, we can ask him if he really wants to leave. Handling the beforeunload event is responsible for this. The event occurs before the unload page unload event. This event allows the web page to trigger a confirmation dialog asking the user if they really want to leave the page. If the user confirms, the browser navigates to a new page, otherwise it cancels the navigation. According to the specification, to display a confirmation dialog, the event handler must call preventDefault() on the event. Apply to body.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;body onbeforeunload=&quot;return myFunction()&quot;&gt;\r\n&lt;script&gt;\r\nfunction myFunction() {\r\n  return &quot;Are you sure you want to close this page?...&quot;;\r\n}\r\n&lt;\/script&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onblur \u2013 loss of focus<\/span><\/h2>\n<p style=\"text-align: justify;\">The focus event is called when the element is focused, and the blur event is called when the element loses focus. focus\/blur support is guaranteed for elements that the visitor can interact with: button, input, select, a, etc. On the other hand, div, span, table formatting elements cannot receive focus by default. The elem.focus() method doesn&#8217;t work for them and the focus\/blur events never fire. This can be changed with the tabindex HTML attribute.<\/p>\n<p style=\"text-align: justify;\">Validation (checking) of entered data with an inscription under the form<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;style&gt;\r\n  .invalid { border-color: red; }\r\n  #error { color: red }\r\n&lt;\/style&gt;\r\n&lt;script&gt;\r\ninput.onblur = function() {\r\n  if (!input.value.includes('@')) { \/\/ not email\r\n    input.classList.add('invalid');\r\n    error.innerHTML = 'Please enter a correct email.'\r\n  }\r\n};\r\ninput.onfocus = function() {\r\n  if (this.classList.contains('invalid')) {\r\n    \/\/ We remove the error indicator, because the user wants to re-enter data\r\n    this.classList.remove('invalid');\r\n    error.innerHTML = &quot;&quot;;\r\n  }\r\n};\r\n&lt;\/script&gt;\r\nYour email: &lt;input type=&quot;email&quot; id=&quot;input&quot;&gt;\r\n&lt;div id=&quot;error&quot;&gt;&lt;\/div&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Validation (checking) of entered data by filling the form with color<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;style&gt;\r\n  .error {\r\n    background: red;\r\n  }\r\n&lt;\/style&gt;\r\n&lt;script&gt;\r\n  input.onblur = function() {\r\n    if (!this.value.includes('@')) { \/\/ \u043d\u0435 email\r\n      \/\/ show error\r\n      this.classList.add(&quot;error&quot;);\r\n      \/\/ ...and return focus back\r\n      input.focus();\r\n    } else {\r\n      this.classList.remove(&quot;error&quot;);\r\n    }\r\n  };\r\n&lt;\/script&gt;\r\nYour email: &lt;input type=&quot;email&quot; id=&quot;input&quot;&gt;\r\n&lt;input type=&quot;text&quot; style=&quot;width:280px&quot; placeholder=&quot;enter an incorrect email and click here&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Changing form text CLICK HERE<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;text&quot; value=&quot;CLICK HERE&quot; \/&gt;\r\n&lt;script&gt;\r\nlet input = document.querySelector(&quot;input&quot;);\r\ninput.onblur = inputBlur;\r\ninput.onfocus = inputFocus;\r\nfunction inputBlur() {\r\n  input.value = &quot;Focus has been lost&quot;;\r\n}\r\nfunction inputFocus() {\r\n  input.value = &quot;Focus is here&quot;;\r\n}\r\n&lt;\/script&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Checking the shape with a frame outline<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html lang=&quot;ru&quot;&gt;\r\n &lt;head&gt;\r\n  &lt;meta charset=&quot;utf-8&quot;&gt;\r\n  &lt;title&gt;Event onblur&lt;\/title&gt;\r\n  &lt;style&gt;\r\n   .warning {\r\n    background-color: #ffe;\r\n    outline: 1px solid #dc143c;\r\n   }\r\n  &lt;\/style&gt;\r\n  &lt;script&gt;\r\n   function warning(field) {\r\n    if (field.value == '') field.classList.add('warning');\r\n    else field.classList.remove('warning');\r\n   }\r\n  &lt;\/script&gt;\r\n &lt;\/head&gt; \r\n &lt;body&gt;\r\n  &lt;form&gt; \r\n   &lt;p&gt;&lt;input placeholder=&quot;Name&quot; onblur=&quot;warning(this)&quot;&gt;&lt;\/p&gt;\r\n   &lt;p&gt;&lt;input placeholder=&quot;Last name&quot; onblur=&quot;warning(this)&quot;&gt;&lt;\/p&gt;\r\n   &lt;p&gt;&lt;input placeholder=&quot;Adress&quot; onblur=&quot;warning(this)&quot;&gt;&lt;\/p&gt;\r\n  &lt;\/form&gt;\r\n &lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Backlight when focusing without onblur<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;style&gt;\r\n*!*input:focus*\/!* {\r\n  background: #FA6;\r\n  outline: none;  \/* remove frame *\/\r\n}\r\n&lt;\/style&gt;\r\n&lt;input type=&quot;text&quot;&gt;\r\n&lt;p&gt;The focus selector will highlight an element when you focus on it and remove the border that the browser uses to highlight this element by default.&lt;\/p&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Placeholder &#8211; a hint value inside an INPUT that automatically disappears when focused and exists until the visitor starts typing, without onblur<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;style&gt;\r\n.my*!*::-webkit-input-placeholder*\/!* {\r\n  color: red;\r\n  font-style: italic;\r\n}\r\n.my*!*::-moz-input-placeholder*\/!* {\r\n  color: red;\r\n  font-style: italic;\r\n}\r\n.my*!*::-ms-input-placeholder*\/!* {\r\n  color: red;\r\n  font-style: italic;\r\n}\r\n&lt;\/style&gt;\r\n&lt;input class=&quot;my&quot; type=&quot;text&quot; placeholder=&quot;E-mail&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">oncancel \u2013 cancel action<\/span><\/h2>\n<p style=\"text-align: justify;\">Cancel the current operation on the device. Used for asynchronous device control. If you perform this function before starting an operation, the operation will be canceled.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\nDevice.Cancel ();\r\n<\/pre>\n<h2><span style=\"color: #008000;\">oncanplay<\/span><\/h2>\n<p style=\"text-align: justify;\">&#8211; you can start playing the specified media file<\/p>\n<p style=\"text-align: justify;\">The oncanplay event occurs when the browser can start playing the specified audio\/video (when it is buffered enough to start). During the audio\/video loading process, the following events occur in this order: onloadstart, ondurationchange, onloadedmetadata, onloadeddata, onprogress, oncanplay, oncanplaythrough<\/p>\n<p style=\"text-align: justify;\">Execute JavaScript when the video is ready to play:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;video oncanplay=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">oncanplaythrough<\/span><\/h2>\n<p style=\"text-align: justify;\">&#8211; You can start playing the specified media file without having to stop for buffering. The oncanplaythrough event occurs when the browser judges that it can play the specified media without having to stop to buffer.<\/p>\n<p style=\"text-align: justify;\">Execute JavaScript when the video can be played in its entirety, without stopping:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;video oncanplaythrough=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onchange \u2013 change value<\/span><\/h2>\n<p style=\"text-align: justify;\">The onchange event occurs when the value of an element has been changed. For radio buttons and checkboxes, the onchange event occurs when the checked state changes. This event is similar to the oninput event. The difference is that the oninput event occurs immediately after the element&#8217;s value changes, while onchange occurs when the element loses focus after the content has changed. Another difference is that the onchange event also works on the select element. A handler for the onchange event, which fires when the element&#8217;s value has changed and it has lost focus. For AudioTrackList, VideoTrackList, and TextTrackList objects, this event occurs when one or more tracks are enabled\/disabled. Executes JavaScript code when the change event occurs; that is, if a Select, Text, or Textarea field loses focus and its value has been changed.<\/p>\n<p style=\"text-align: justify;\">type &#8211; Indicates the event type.<br \/>\ntarget &#8211; Indicates the object to which the event was originally sent<\/p>\n<p style=\"text-align: justify;\">Run JavaScript when the user changes the selected option of a select element:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;select onchange=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Here userName is a text field. If the user changes the text and leaves the field, the onChange handler calls the checkValue function to confirm that userName is valid:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;INPUT TYPE=&quot;text&quot; VALUE=&quot;&quot; NAME=&quot;userName&quot; onChange=&quot;checkValue(this.value)&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onclose \u2013 closing something<\/span><\/h2>\n<p style=\"text-align: justify;\">An event handler for close events is sent to the window. The OnClose event occurs when the dialog box is closed. You can create an event handler for the OnClose event to perform specific actions when the dialog box is closed. A handler for the close event, which is raised on dialog elements when they are closed and on WebSocket elements when the connection is completed.<\/p>\n<h2><span style=\"color: #008000;\">oncontextmenu \u2013 opening context menu<\/span><\/h2>\n<p style=\"text-align: justify;\">The oncontextmenu event occurs when the user right-clicks an HTML element to open the context menu. Event handler property for the right-click event inside the window element. If the standard behavior is not prevented, the browser context menu is activated (There is a bug in IE8 that the context menu will not be activated if a contextmenu event handler is defined). The event will occur along with other right-click events and is independent of the element&#8217;s &#8220;contextmenu&#8221; attribute.<\/p>\n<p style=\"text-align: justify;\">Run JavaScript when user right clicks on div element with context menu:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;div oncontextmenu=&quot;myFunction()&quot; contextmenu=&quot;mymenu&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">The code in this example changes the default behavior of the browser by disabling right-click.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\ndocument.oncontextmenu = function () {\r\n  \/\/Use object &quot;document&quot; instead of &quot;window&quot; for compatibility with IE8.\r\n  return false;\r\n};\r\nwindow.addEventListener(\r\n  &quot;contextmenu&quot;,\r\n  function (e) {\r\n    \/\/ Not compatible with IE versions earlier than 9\r\n    e.preventDefault();\r\n  },\r\n  false,\r\n);\r\n<\/pre>\n<h2><span style=\"color: #008000;\">oncopy \u2013 copy completed<\/span><\/h2>\n<p style=\"text-align: justify;\">The oncopy event occurs when the user copies the content of an element. The oncopy event also occurs when the user copies an element, such as an image created using the img element. The oncopy event is mainly used for &#8220;input&#8221; elements with type=&#8221;text&#8221;. Triggered when inserting\/copying\/deleting text. If you cancel the browser action in their handlers, then insertion\/copying\/deleting will not occur. The inserted value cannot be obtained: at the time the event is triggered, the element still has the old value, and the new one is not available.<\/p>\n<p style=\"text-align: justify;\">Execute JavaScript when copying some input element text:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;text&quot; oncopy=&quot;myFunction()&quot; value=&quot;Try copying this text&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">oncuechange &#8211; changing the label in the track element<\/span><\/h2>\n<p style=\"text-align: justify;\">A handler for the cuechange event, which fires when the TextTrack element changes the currently displayed timestamps (cue).<\/p>\n<h2><span style=\"color: #008000;\">oncut \u2013 content has been cut<\/span><\/h2>\n<p style=\"text-align: justify;\">The oncut event occurs when the user cuts the content of an element. Although the oncut event is supported by all HTML elements, it is not actually possible to cut content in, for example, a p element UNLESS the element has set contenteditable to &#8220;true&#8221;. The oncut event is mainly used for input elements with type=&#8221;text&#8221;.<\/p>\n<p style=\"text-align: justify;\">Execute JavaScript when cutting out some text in an input element:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;text&quot; oncut=&quot;myFunction()&quot; value=&quot;Try shortening this text&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">ondblclick \u2013 double click on an element<\/span><\/h2>\n<p style=\"text-align: justify;\">A handler for the dblclick event, which occurs when the left mouse button is double-clicked. The ondblclick event occurs when the user double-clicks an HTML element; that is, when the user double-clicks a form element or hyperlink.<\/p>\n<p style=\"text-align: justify;\">type &#8211; Indicates the event type.<br \/> <br \/>\ntarget &#8211; Indicates the object to which the event was originally sent.<br \/> <br \/>\nlayerX, layerY, pageX, pageY, screenX, screenY &#8211; Represents the location of the cursor when the event occurs.<br \/> <br \/>\nwhich &#8211; Represents 1 for a left mouse click and 3 for a right mouse click.<br \/> <br \/>\nmodifiers &#8211; Contains a list of modifier keys pressed when the event occurs.<\/p>\n<p style=\"text-align: justify;\">Run JavaScript when double clicking on an element p:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;p ondblclick=&quot;myFunction()&quot;&gt;Double click me&lt;\/p&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Here the alert dialog is displayed if the user double clicks the button:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;form&gt;\r\n&lt;INPUT Type=&quot;button&quot; Value=&quot;Double Click Me!&quot; onDblClick=&quot;alert('You just double clicked me!')&quot;&gt;\r\n&lt;\/form&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">ondrag &#8211; dragging an element<\/span><\/h2>\n<p style=\"text-align: justify;\">The ondrag event occurs when an element or selected text is dragged. Drag and drop is a very common feature in HTML5. This is when you &#8220;grab&#8221; an object and drag it to another location.<\/p>\n<p style=\"text-align: justify;\">type &#8211; Indicates the event type.<br \/>\ntarget &#8211; Indicates the object to which the event was originally sent.<br \/>\ndata &#8211; Returns an array of strings containing the URLs of the released objects.<br \/>\nmodifiers &#8211; Contains a list of modifier keys pressed when the event occurs.<br \/>\nscreenX, screenY &#8211; Represents the location of the cursor when the event occurs.<\/p>\n<p style=\"text-align: justify;\">Execute JavaScript when p element is dragged:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;p draggable=&quot;true&quot; ondrag=&quot;myFunction(event)&quot;&gt;Drag me!&lt;\/p&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">ondragend &#8211; element dragging completed<\/span><\/h2>\n<p style=\"text-align: justify;\">The ondragend event occurs when the user has finished dragging an element or text selection.<\/p>\n<p style=\"text-align: justify;\">Run JavaScript when the user finishes dragging an element p:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;p draggable=&quot;true&quot; ondragend=&quot;myFunction(event)&quot;&gt;Drag me!&lt;\/p&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">ondragenter<\/span><\/h2>\n<p style=\"text-align: justify;\">&#8211; the element is dragged to a valid target zone. The ondragenter event occurs when the dragged element or selected text hits a valid delete target. The ondragenter and ondragleave events can help the user understand that the dragged element is about to enter or leave the drop target. This can be done, for example, by setting the background color when the dragged element hits the drag target, and clearing the color when the element is moved away from the target.<\/p>\n<p style=\"text-align: justify;\">Execute JavaScript when the dragged element hits the drag target:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;div ondragenter=&quot;myFunction(event)&quot;&gt;&lt;\/div&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">ondragexit<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 exit drag and drop mode. A handler for the dragexit event, which occurs when an element is no longer the target of an element that can accept it.<\/p>\n<h2><span style=\"color: #008000;\">ondragleave<\/span><\/h2>\n<p style=\"text-align: justify;\">&#8211; element leaves a valid target. The ondragleave event occurs when a dragged element or text selection leaves a valid drop target.<\/p>\n<p style=\"text-align: justify;\">Execute JavaScript when the dragged element moves away from the drag target:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;div ondragleave=&quot;myFunction(event)&quot;&gt;&lt;\/div&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">ondragover<\/span><\/h2>\n<p style=\"text-align: justify;\">&#8211; the element is dragged to a valid target point. The ondragover event occurs when a dragged element or selected text is dragged over a valid drop target. By default, data\/elements cannot be removed from other elements. To allow deletion, we must disable element processing by default. This is done by calling the event.preventDefault() method on the ondragover event.<\/p>\n<p style=\"text-align: justify;\">Execute JavaScript when an element is dragged on top of the drag target:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;div ondragover=&quot;myFunction(event)&quot;&gt;&lt;\/div&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">ondragstart<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 start of drag and drop operation. The ondragstart event occurs when the user starts dragging an element or selected text.<\/p>\n<p style=\"text-align: justify;\">Run JavaScript when the user starts dragging an element p:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;p draggable=&quot;true&quot; ondragstart=&quot;myFunction(event)&quot;&gt;Drag me!&lt;\/p&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">ondrop<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 the dragged element is released. The ondrop event occurs when a dragged element or selected text is dropped onto a valid drop target.<\/p>\n<p style=\"text-align: justify;\">Execute JavaScript when a dragged element is removed in an element div:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;div ondrop=&quot;myFunction(event)&quot;&gt;&lt;\/div&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">ondurationchange<\/span><\/h2>\n<p style=\"text-align: justify;\">&#8211; change in media length. The ondurationchange event occurs when the duration of the audio\/video changes. When loading audio\/video, the duration will change from &#8220;NaN&#8221; to the actual duration of the audio\/video. During the audio\/video loading process, the following events occur in this order: onloadstart, ondurationchange, onloadedmetadata, onloadeddata, onprogress, oncanplay, oncanplaythrough<\/p>\n<p style=\"text-align: justify;\">Run JavaScript when video length has changed:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;video ondurationchange=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onemptied<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 The file suddenly became unavailable. A handler for the emptied event, which occurs when the current playlist for an audio or video element is empty. Most often due to a connection failure.<\/p>\n<h2><span style=\"color: #008000;\">onended<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 playback is complete. The onended event occurs when the audio\/video reaches the end. This event is useful for messages like &#8220;thanks for listening&#8221;, &#8220;thanks for watching&#8221;, etc.<\/p>\n<p style=\"text-align: justify;\">Run JavaScript when audio ends:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;audio onended=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onerror<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 an error occurred. The onerror event is fired if an error occurs while loading an external file (such as a document or image). When used on audio\/video media, related events that occur when there is any disruption to the media loading process are: onabort, onemptied, onstalled, onsuspend.<\/p>\n<p style=\"text-align: justify;\">The error event occurs only when a JavaScript syntax error or runtime error occurs, not when a browser error occurs. For example, if you try to install window.location.href=&#8217;notThere.html&#8217;, and file notThere.html does not exist, the resulting error message will be a browser message; hence onError will not intercept this message. However, the error event will be triggered by an invalid URL in the IMG tag or invalid image data.<\/p>\n<p style=\"text-align: justify;\">window.onerror applies only to errors that occur in the window containing window.onerror, not to errors in other windows.<\/p>\n<p style=\"text-align: justify;\">onError may have the following meanings:<br \/>\n&#8211; null to suppress all JavaScript error dialogs. Setting window.onerror to null means that your users won&#8217;t see JavaScript errors caused by your code.<br \/>\n&#8211; The name of the function that handles errors (arguments are the message text, URL, and line number with the error). To suppress standard JavaScript error dialog, this function must return true. See Example 3 below.<br \/>\n&#8211; Variable or property containing null or a valid function reference.<br \/>\nIf you are writing an error handler function, you have three options for reporting errors:<br \/>\n&#8211; Track errors, but allow them to be reported via a standard JavaScript dialog (use an error handling function that returns false or does not return a value).<br \/>\n&#8211; Report errors yourself and disable the standard dialog (use an error handling function that returns true).<br \/>\n&#8211; Disable all error messages (set null in onError handler).<\/p>\n<p style=\"text-align: justify;\">type &#8211; Indicates the event type.<br \/>\ntarget &#8211; Indicates the object to which the event was originally sent<\/p>\n<p style=\"text-align: justify;\">Run JavaScript if an error occurs while loading an image:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;img src=&quot;image.gif&quot; onerror=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Example 1: Handler with Null value. In this IMG tag, the onError=&#8221;null&#8221; code suppresses error messages if an error occurs while loading the image.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;IMG NAME=&quot;imageBad1&quot; SRC=&quot;corrupt.gif&quot; ALIGN=&quot;left&quot; BORDER=&quot;2&quot; onError=&quot;null&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Example 2: Null handler for a window. The onError handler for a window cannot be expressed via HTML. Therefore, you must enter everything necessary, in lower case, in the SCRIPT tag. The following code assigns null to the onError handler for the entire window, not just the Image object. This suppresses all JavaScript error messages, including those for the object Image.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;SCRIPT&gt;\r\nwindow.onerror=null\r\n&lt;\/SCRIPT&gt;\r\n&lt;IMG NAME=&quot;imageBad1&quot; SRC=&quot;corrupt.gif&quot; ALIGN=&quot;left&quot; BORDER=&quot;2&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">However, if the Image object has its own special onError handler, that handler will be executed when an error occurs with the image. This occurs because window.onerror=null suppresses JavaScript error messages, not onError handlers.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;SCRIPT&gt;\r\nwindow.onerror=null\r\nfunction myErrorFunc() {\r\n   alert(&quot;The image had a nasty error.&quot;)\r\n}\r\n&lt;\/SCRIPT&gt;\r\n&lt;IMG NAME=&quot;imageBad1&quot; SRC=&quot;corrupt.gif&quot; ALIGN=&quot;left&quot; BORDER=&quot;2&quot; onError=&quot;myErrorFunc()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">In the following example, window.onerror=null suppresses all error messages. Without onerror=null the code will cause a stack overflow error because there is infinite recursion.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;SCRIPT&gt;\r\nwindow.onerror = null;\r\nfunction testErrorFunction() {\r\n   testErrorFunction();\r\n}\r\n&lt;\/SCRIPT&gt;\r\n&lt;BODY onload=&quot;testErrorFunction()&quot;&gt;\r\ntest message\r\n&lt;\/BODY&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Example 3: Error handling function. The function myOnError is defined here, which catches JavaScript errors. This function uses three arrays to store the message, URL, and offending string for each error. If the user clicks the Display Error Report button, the displayErrors function opens a window and generates an error message in it. Note that this function returns true to suppress the standard JavaScript error dialog.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;SCRIPT&gt;\r\nwindow.onerror = myOnError\r\nmsgArray = new Array()\r\nurlArray = new Array()\r\nlnoArray = new Array()\r\nfunction myOnError(msg, url, lno) {\r\n   msgArray&#x5B;msgArray.length]\r\n= msg\r\n   urlArray&#x5B;urlArray.length] = url\r\n   lnoArray&#x5B;lnoArray.length]\r\n= lno\r\n   return true\r\n}\r\nfunction displayErrors() {\r\n   win2=window.open('','window2','scrollbars=yes')\r\n   win2.document.writeln('&lt;B&gt;Error Report&lt;\/B&gt;&lt;P&gt;')\r\n   for (var i=0; i &lt; msgArray.length; i++) {\r\n      win2.document.writeln('&lt;B&gt;Error in file:&lt;\/B&gt; '\r\n+ urlArray&#x5B;i] + '&lt;BR&gt;')\r\n      win2.document.writeln('&lt;B&gt;Line\r\nnumber:&lt;\/B&gt; ' + lnoArray&#x5B;i] + '&lt;BR&gt;')\r\n      win2.document.writeln('&lt;B&gt;Message:&lt;\/B&gt; '\r\n+ msgArray&#x5B;i] + '&lt;P&gt;')\r\n   }\r\n   win2.document.close()\r\n}\r\n&lt;\/SCRIPT&gt;\r\n&lt;BODY onload=&quot;noSuchFunction()&quot;&gt;\r\n&lt;FORM&gt;\r\n&lt;BR&gt;&lt;INPUT TYPE=&quot;button&quot; VALUE=&quot;This button has a syntax error&quot; onClick=&quot;alert('unterminated string')&quot;&gt;\r\n&lt;P&gt;&lt;INPUT TYPE=&quot;button&quot; VALUE=&quot;Display Error Report&quot; onClick=&quot;displayErrors()&quot;&gt;\r\n&lt;\/FORM&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">This example will give the output:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\nError Report\r\nError in file:\r\nfile:\/\/\/c%7C\/temp\/onerror.html\r\nLine number: 34\r\nMessage: unterminated string literal\r\nError in file: file:\/\/\/c%7C\/temp\/onerror.html\r\nLine number:\r\n34\r\nMessage: missing ) after argument list\r\nError in file: file:\/\/\/c%7C\/temp\/onerror.html\r\nLine number: 30\r\nMessage: noSuchFunction is not defined\r\n<\/pre>\n<p style=\"text-align: justify;\">Example 4: An event handler calls a function. In the IMG tag, the onError handler calls the badImage function when errors occur while loading the image.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;SCRIPT&gt;\r\nfunction badImage(theImage) {\r\n   alert('Error: ' + theImage.name + ' did not load properly.')\r\n}\r\n&lt;\/SCRIPT&gt;\r\n&lt;FORM&gt;\r\n&lt;IMG NAME=&quot;imageBad2&quot; SRC=&quot;orca.gif&quot; ALIGN=&quot;left&quot; BORDER=&quot;2&quot; onError=&quot;badImage(this)&quot;&gt;\r\n&lt;\/FORM&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onfocus<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 setting focus on an element. Executes JavaScript code when the focus event occurs; that is, if a window, frame, or set of frames receives focus or if a form element receives focus. The onfocus event occurs when an element receives focus. The onfocus event is often used in input fields. All HTML elements EXCEPT: base, bdo, br, head, html, iframe, meta, param, script, style, \u0438 title<\/p>\n<p style=\"text-align: justify;\">Run JavaScript when the input field receives focus:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;text&quot; onfocus=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Here the onFocus handler is used on the valueField Textarea object to call the valueCheck function.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;INPUT TYPE=&quot;textarea&quot; VALUE=&quot;&quot; NAME=&quot;valueField&quot; onFocus=&quot;valueCheck()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onfocusin<\/span><\/h2>\n<p style=\"text-align: justify;\">The onfocusin event occurs when an element receives focus. The onfocusin event is often used in input fields. All HTML elements EXCEPT: base, bdo, br, head, html, iframe, meta, param, script, style, \u0438 title<\/p>\n<p style=\"text-align: justify;\">Run JavaScript when an input field is about to receive focus:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;text&quot; onfocusin=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onfocusout<\/span><\/h2>\n<p style=\"text-align: justify;\">The onfocusout event occurs when an element loses focus. The onfocusout event is often used in input fields. The onfocusout event is often used during form validation (when the user leaves the form field). All HTML elements EXCEPT: base, bdo, br, head, html, iframe, meta, param, script, style, \u0438 title<\/p>\n<p style=\"text-align: justify;\">Run JavaScript when an input field is about to lose focus:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;text&quot; onfocusout=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onfullscreenchange<\/span><\/h2>\n<p style=\"text-align: justify;\">The fullscreenchange event occurs when an element is viewed in full screen mode. Use the element.requestFullscreen() method to view the element in full screen mode. Use the element.exitFullscreen() method to cancel full screen mode. Each browser requires a specific prefix (see parentheses): 45.0 (webkit), 11.0 (ms), 47.0 (moz), 5.1 (webkit), 15.0 (webkit)<\/p>\n<p style=\"text-align: justify;\">Display some text when viewing a page in full screen mode:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\ndocument.addEventListener(&quot;fullscreenchange&quot;, function() {\r\n  output.innerHTML = &quot;fullscreenchange event fired!&quot;;\r\n});\r\n<\/pre>\n<p style=\"text-align: justify;\">Use prefixes for cross-browser code:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/* \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 *\/\r\ndocument.addEventListener(&quot;fullscreenchange&quot;, function() {\r\n  ...\r\n});\r\n\/* Firefox *\/\r\ndocument.addEventListener(&quot;mozfullscreenchange&quot;, function() {\r\n  ...\r\n});\r\n\/* Chrome, Safari and Opera *\/\r\ndocument.addEventListener(&quot;webkitfullscreenchange&quot;, function() {\r\n  ...\r\n});\r\n\/* IE \/ Edge *\/\r\ndocument.addEventListener(&quot;msfullscreenchange&quot;, function() {\r\n  ...\r\n});\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onfullscreenerror<\/span><\/h2>\n<p style=\"text-align: justify;\">The fullscreenerror event occurs when an element cannot be viewed in full screen mode, even though it was requested. Use the element.requestFullscreen() method to view the element in full screen mode. Use element.exitFullscreen() method to cancel full screen mode.<\/p>\n<p style=\"text-align: justify;\">Warning text if the element cannot be viewed in full screen mode:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\ndocument.addEventListener(&quot;fullscreenerror&quot;, function() {\r\n  alert(&quot;Fullscreen denied&quot;)\r\n});\r\n<\/pre>\n<p style=\"text-align: justify;\">Use prefixes for cross-browser code:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/* \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 *\/\r\ndocument.addEventListener(&quot;fullscreenerror&quot;, function() {\r\n  ...\r\n});\r\n\/* Firefox *\/\r\ndocument.addEventListener(&quot;mozfullscreenerror&quot;, function() {\r\n  ...\r\n});\r\n\/* Chrome, Safari and Opera *\/\r\ndocument.addEventListener(&quot;webkitfullscreenerror&quot;, function() {\r\n  ...\r\n});\r\n\/* IE \/ Edge *\/\r\ndocument.addEventListener(&quot;msfullscreenerror&quot;, function() {\r\n  ...\r\n});\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onhashchange<\/span><\/h2>\n<p style=\"text-align: justify;\">&#8211; changing the binding of part of the address. HTML tag support: body. The onhashchange event occurs when changes have been made to the anchor portion (starts with the &#8216;#&#8217; character) of the current URL. An example of what the anchor part actually is: Let&#8217;s say the current URL is http:\/\/www.example.com\/test.htm#part2 &#8211; The anchor part of that URL would be #part2.<br \/>\nTo trigger this event you can:<br \/>\nChange the binding part by setting the location.hash or location.href property of the Location object<br \/>\nGo to the current page with another bookmark (use the back or forward buttons)<br \/>\nClick on the bookmark anchor link<\/p>\n<p style=\"text-align: justify;\">Execute JavaScript when part of the binding has changed:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;body onhashchange=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">How to assign an &#8220;onhashchange&#8221; event to a window object:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nwindow.onhashchange = myFunction;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">oninput<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 start of data entry. The oninput event occurs when the element receives user input. This event occurs when the value of an input or textarea element changes. This event is similar to the onchange event. The difference is that the oninput event occurs immediately after the element&#8217;s value changes, while onchange occurs when the element loses focus after its content has changed. Another difference is that the onchange event also works on select elements. HTML tag support: input type=&#8221;color&#8221;, input type=&#8221;date&#8221;, input type=&#8221;datetime&#8221;, input type=&#8221;email&#8221;, input type=&#8221;month&#8221;, input type=&#8221;number&#8221;, input type=&#8221;password&#8221;, input type=&#8221;range&#8221;, input type=&#8221;search&#8221;, input type=&#8221;tel&#8221;, input type=&#8221;text&#8221;, input type=&#8221;time&#8221;, input type=&#8221;url&#8221;, input type=&#8221;week&#8221; and textarea<\/p>\n<p style=\"text-align: justify;\">Execute JavaScript when the user writes something in the input field:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;text&quot; oninput=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Range Slider &#8211; How to dynamically update the slider value:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;range&quot; oninput=&quot;myFunction(this.value)&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">oninvalid<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 the item is damaged. The oninvalid event occurs when the input element being sent is invalid. For example, an input field is invalid if the required attribute is set and the field is empty (the required attribute specifies that the input field must be filled in before the form can be submitted). HTML tag support: input<\/p>\n<p style=\"text-align: justify;\">Warning about some text if the input field is invalid:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;text&quot; oninvalid=&quot;alert('You must fill out the form!');&quot; required&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Warning text if input field contains less than 6 characters:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n\u0418\u043c\u044f: &lt;input type=&quot;text&quot; id=&quot;myInput&quot; name=&quot;fname&quot; pattern=&quot;.{6,}&quot; required&gt;\r\n&lt;script&gt;\r\ndocument.getElementById(&quot;myInput&quot;).addEventListener(&quot;invalid&quot;, myFunction);\r\nfunction myFunction() {\r\n  alert(&quot;Must contain 6 or more characters&quot;);\r\n}\r\n&lt;\/script&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Warning text if the input field contains a number that is less than 2 or greater than 5:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n\u041d\u043e\u043c\u0435\u0440: &lt;input type=&quot;number&quot; id=&quot;myInput&quot; name=&quot;quantity&quot; min=&quot;2&quot; max=&quot;5&quot; required&gt;\r\n&lt;script&gt;\r\ndocument.getElementById(&quot;myInput&quot;).addEventListener(&quot;invalid&quot;, myFunction);\r\nfunction myFunction() {\r\n  alert(&quot;You must choose a number from 2 to 5. You have chosen: &quot; + this.value);\r\n}\r\n&lt;\/script&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onkeydown<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 key pressed. The onkeydown event occurs when the user presses a key (on the keyboard). The order of events associated with the onkeydown event is: onkeydown, onkeypress, onkeyup. All HTML elements EXCEPT: base, bdo, br, head, html, iframe, meta, param, script, style, \u0438 title. The KeyDown event always occurs before the KeyPress event. If onKeyDown returns false, the KeyPress event is not raised. This prevents KeyPress events from occurring when the user holds down a key.<\/p>\n<p style=\"text-align: justify;\">type &#8211; Indicates the event type.<br \/>\ntarget &#8211; Indicates the object to which the event was originally sent.<br \/>\nlayerX, layerY, pageX, pageY, screenX, screenY &#8211; For an over-window event, represents the location of the cursor at the time the event occurred. For an event on top of a form, represents the position of the form element.<br \/>\nwhich &#8211; ASCII-the value of the key pressed. To get the actual letter, number, or character of the key pressed, use the String.fromCharCode method. To set this property when the ASCII value is unknown, use the String.charCodeAt.<br \/>\nmodifiers &#8211; Contains a list of modifier keys pressed when the event occurs.<\/p>\n<p style=\"text-align: justify;\">Run JavaScript when the user presses a key:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;text&quot; onkeydown=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Use &#8220;onkeydown&#8221; with event &#8220;onkeyup&#8221;:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;text&quot; onkeydown=&quot;keydownFunction()&quot; onkeyup=&quot;keyupFunction()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Here the blockA function is used to calculate the characters entered from the keyboard into the textentry text box. If the user enters &#8220;a&#8221; or &#8220;A&#8221;, the function returns false and the text box does not display a value. In this function, the which property of the event assigns the ASCII value of the user&#8217;s key pressed to the keyChar variable. The if statement evaluates keyChar and returns false for the specified characters:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;form name=&quot;main&quot;&gt;\r\n   &lt;input name=&quot;textentry&quot;\r\ntype=text size=10 maxlength=10&gt;\r\n&lt;\/form&gt;\r\n&lt;script&gt;\r\nfunction blockA(e) {\r\nvar keyChar = String.fromCharCode(e.which);\r\nif (keyChar == 'A' || keyChar == 'a')\r\nreturn false;\r\n}\r\ndocument.main.textentry.onkeydown = blockA;\r\n&lt;\/script&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onkeypress<\/span><\/h2>\n<p style=\"text-align: justify;\">&#8211; a key is pressed and then released. Executes JavaScript code when the KeyPress event occurs; that is, if the user holds down the key. The onkeypress event occurs when the user presses a key (on the keyboard). The onkeypress event does not fire for all keys (e.g. ALT, CTRL, SHIFT, ESC) in all browsers. To detect only whether the user pressed a key, use the onkeydown event instead because it works for all keys. The order of events associated with the onkeydown event is: onkeydown, onkeypress, onkeyup. All HTML elements EXCEPT: base, bdo, br, head, html, iframe, meta, param, script, style, \u0438 title. The KeyPress event fires immediately after the KeyDown event only when onKeyDown returns something other than false. The KeyPress event occurs repeatedly until the user releases the key. You can cancel individual KeyPress events.<\/p>\n<p style=\"text-align: justify;\">type &#8211; Indicates the event type.<br \/>\ntarget &#8211; Indicates the object to which the event was originally sent.<br \/>\nlayerX, layerY, pageX, pageY, screenX, screenY &#8211; For an event, the overlay represents the location of the cursor at the time the event occurred. For an over-form event, represents the position of a form element.<br \/>\nwhich &#8211; ASCII-the value of the key pressed. To get the actual letter, number, or character of the key pressed, use the String.fromCharCode method. To set this property when the ASCII value is unknown, use the String.charCodeAt.<br \/>\nmodifiers &#8211; Contains a list of modifier keys pressed when the event occurs.<\/p>\n<p style=\"text-align: justify;\">Run JavaScript when the user presses a key:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;text&quot; onkeypress=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Here, the captureEvents method captures keyboard input, and the onKeyPress handler calls the blockA function to check for keypresses. If the &#8220;a&#8221; or &#8220;z&#8221; keys are pressed, the function scrolls the Navigator window.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction blockA(e) {\r\nvar keyChar = String.fromCharCode(e.which);\r\nif (keyChar == 'A' || keyChar == 'a')\r\nself.scrollBy(10,10);\r\nelse if(keyChar == 'Z' || keyChar == 'z')\r\nself.scrollBy(-10,-10);\r\nelse return false;\r\n}\r\ndocument.captureEvents(Event.KEYPRESS);\r\ndocument.onkeypress = blockA;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onkeyup<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 key released. The onkeyup event occurs when the user releases a key (on the keyboard). The order of events associated with the onkeydown event is: onkeydown, onkeypress, onkeyup. All HTML elements EXCEPT: base, bdo, br, head, html, iframe, meta, param, script, style, and title.<\/p>\n<p style=\"text-align: justify;\">type &#8211; Indicates the event type.<br \/>\ntarget &#8211; Indicates the object to which the event was originally sent.<br \/>\nlayerX, layerY, pageX, pageY, screenX, screenY &#8211; For an event, the overlay represents the location of the cursor at the time the event occurred. For an over-form event, represents the position of a form element.<br \/>\nwhich &#8211; ASCII-the value of the key pressed. To get the actual letter, number, or character of the key pressed, use the String.fromCharCode method. To set this property when the ASCII value is unknown, use the String.charCodeAt.<br \/>\nmodifiers &#8211; Contains a list of modifier keys pressed when the event occurs.<\/p>\n<p style=\"text-align: justify;\">Run JavaScript when the user releases the key:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;text&quot; onkeyup=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Use &#8220;onkeydown&#8221; with the &#8220;onkeyup&#8221; event:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;text&quot; onkeydown=&quot;keydownFunction()&quot; onkeyup=&quot;keyupFunction()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Output the actual key that was issued inside the text field:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0441\u0432\u043e\u0435 \u0438\u043c\u044f: &lt;input type=&quot;text&quot; id=&quot;fname&quot; onkeyup=&quot;myFunction()&quot;&gt;\r\n&lt;script&gt;\r\nfunction myFunction() {\r\n  var x = document.getElementById(&quot;fname&quot;).value;\r\n  document.getElementById(&quot;demo&quot;).innerHTML = x;\r\n}\r\n&lt;\/script&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Here, the captureEvents method captures keyboard input, and the onKeyUp handler calls the Key_Up function. The function&#8217;s alert method opens a dialog box to display the value of the key pressed:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction Key_Up(e) {\r\nvar keyChar = String.fromCharCode(e.which);\r\nalert(&quot;Hold '&quot; + keyChar +&quot;' again for me, okay?&quot;);\r\n}\r\ndocument.onkeyup=Key_Up;\r\ndocument.captureEvents(Event.KEYUP);\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onload<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 item loaded. The onload event occurs when an object has been loaded. The onload event is most often used on the body element to execute a script after the web page has fully loaded all of its content (including images, script files, CSS files, etc.). The onload event can be used to check the visitor&#8217;s browser type and browser version and load the appropriate version of the web page based on the information received. The onload event can also be used to handle cookies.<\/p>\n<p style=\"text-align: justify;\">The onLoad handler is used in the BODY or FRAMESET tag, for example, BODY onLoad=&#8221;&#8230;&#8221;. For FRAMESET and FRAME tags: the onLoad handler event in the frame (placed in the BODY tag) occurs before the onLoad of the FRAMESET tag (placed in the FRAMESET tag). For images, the onLoad handler specifies the script to be executed when the image is output. Don&#8217;t confuse image output with image upload. You can load multiple images, then display them one at a time in the same Image object by setting the object&#8217;s src property. If you change the image output this way, onLoad is executed every time the image is output, not just when the images are loaded into memory.<\/p>\n<p style=\"text-align: justify;\">If you specify an onLoad handler for an Image object that outputs a looping GIF (multi-image GIF), each animation loop includes an onLoad handler, and the handler is executed once for each loop. You can use the onLoad handler to create a JavaScript animation by repeatedly setting the src property of the Image object.<\/p>\n<p style=\"text-align: justify;\">type &#8211; Indicates the event type.<br \/>\ntarget &#8211; Indicates the object to which the event was originally sent.<br \/>\nwidth, height &#8211; For an event on top of a window, but not on top of a layer, these properties represent the window&#8217;s width and height.<\/p>\n<p style=\"text-align: justify;\">Run JavaScript immediately after page loads:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;body onload=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">In JavaScript, use the method addEventListener():<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nobject.addEventListener(&quot;load&quot;, myScript);\r\n<\/pre>\n<p style=\"text-align: justify;\">Display a message when the page loads. Here the onLoad handler prints a greeting after the page has loaded.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;BODY onLoad=&quot;window.alert(&quot;Welcome to the Brave New World home page!&quot;)&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Display a message when loading an image. Here two Image objects are created: one by the Image constructor, and the second by the IMG tag. Each Image object has an onLoad handler that calls the displayAlert function, which displays a message. For an image created by an IMG tag, the alert dialog displays the name of the image. For an image created by the Image constructor, alert displays a message without the image name. This occurs because the onLoad handler for the object created by the Image constructor must be the name of a function and it cannot specify parameters for the displayAlert function.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;SCRIPT&gt;\r\nimageA = new Image(50,50)\r\nimageA.onload=displayAlert\r\nimageA.src=&quot;cyanball.gif&quot;\r\nfunction displayAlert(theImage) {\r\n   if (theImage==null) {\r\n      alert('An image loaded')\r\n   }\r\n   else alert(theImage.name + ' has been loaded.')\r\n}\r\n&lt;\/SCRIPT&gt;\r\n&lt;IMG NAME=&quot;imageB&quot; SRC=&quot;greenball.gif&quot; ALIGN=&quot;top&quot; onLoad=displayAlert(this)&gt;&lt;BR&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Looping GIF animation output. The image displayed here is birdie.gif, which is an animated GIF image. The onLoad handler increments the cycles variable, which tracks the number of animation cycles. To see the value of cycles, the user clicks the Count Loops button.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;SCRIPT&gt;\r\nvar cycles=0\r\n&lt;\/SCRIPT&gt;\r\n&lt;IMG ALIGN=&quot;top&quot; SRC=&quot;birdie.gif&quot; BORDER=0 onLoad=&quot;++cycles&quot;&gt;\r\n&lt;INPUT TYPE=&quot;button&quot; VALUE=&quot;Count Loops&quot; onClick=&quot;alert('The animation has looped ' + cycles + ' times.')&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Change the GIF animation displayed. This example uses the onLoad handler to rotate six GIF animations. Each animation is shown as a sequence of individual Image objects. When the document is loaded, !anim0.html is output. When this animation completes, the onLoad handler causes the next file, !anim1.html, to be loaded instead of the first file. After the last animation, !anim5.html, completes, the first file is displayed again. Note that the changeAnimation function does not call itself after changing the src property of the Image object. This happens because the src property is changed, the image&#8217;s onLoad handler is enabled, and the changeAnimation function is called.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;SCRIPT&gt;\r\nvar whichImage=0\r\nvar maxImages=5\r\nfunction changeAnimation(theImage) {\r\n   ++whichImage\r\n   if (whichImage &lt;= maxImages) {\r\n      var imageName=&quot;!anim&quot; + whichImage + &quot;.gif&quot;\r\n      theImage.src=imageName\r\n   } else {\r\n      whichImage=-1\r\n      return\r\n   }\r\n}\r\n&lt;\/SCRIPT&gt;\r\n&lt;IMG NAME=&quot;changingAnimation&quot; SRC=&quot;!anim0.gif&quot; BORDER=0 ALIGN=&quot;top&quot; onLoad=&quot;changeAnimation(this)&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Use the onload event for the img element. &#8220;Image Loaded&#8221; notification immediately after the image is loaded:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;img src=&quot;javascriptw3.gif&quot; onload=&quot;loadImage()&quot; width=&quot;100&quot; height=&quot;132&quot;&gt;\r\n&lt;script&gt;\r\nfunction loadImage() {\r\n  alert(&quot;Image is loaded&quot;);\r\n}\r\n&lt;\/script&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Use onload event to handle cookies:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;body onload=&quot;checkCookies()&quot;&gt;\r\n&lt;script&gt;\r\nfunction checkCookies() {\r\n  var text = &quot;&quot;;\r\n  if (navigator.cookieEnabled == true) {\r\n    text = &quot;Cookies enabled.&quot;;\r\n  } else {\r\n     text = &quot;Cookies are not enabled.&quot;;\r\n  }\r\n  document.getElementById(&quot;demo&quot;).innerHTML = text;\r\n}\r\n&lt;\/script&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onloadeddata<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 file data loaded. Handler for the loadeddata event, which occurs when the audio\/video can already be played at the current position, but media data continues to be loaded. The onloadeddata event occurs when the media frame is loaded, but does not guarantee that enough data is available to begin playback. The onloadeddata event occurs after onloadedmetadata and before oncanplay.<\/p>\n<p style=\"text-align: justify;\">When loading media, 7 events occur in the following order:<br \/>\n1. onloadstart<br \/>\n2. ondurationchange<br \/>\n3. onloadedmetadata<br \/>\n4. onloadeddata<br \/>\n5. onprogress<br \/>\n6. oncanplay<br \/>\n7. oncanplaythrough<\/p>\n<p style=\"text-align: justify;\">Execute JavaScript when data is available for the current frame (for video):<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;video onloadeddata=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Execute JavaScript when data is available for the current frame (for audio):<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;audio onloadeddata=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onloadedmetadata<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 file metadata loaded. Handler for the loadedmetadata event, which occurs when metadata (duration, frame dimensions (for video) and track text) for the specified audio\/video file has been loaded. The onloadedmetadata event occurs when metadata for the media has been loaded.<\/p>\n<p style=\"text-align: justify;\">Metadata for audio or video consists of:<br \/>\nDuration<br \/>\nDimensions (video)<br \/>\nTracks<\/p>\n<p style=\"text-align: justify;\">Run JavaScript when loading video metadata:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;video onloadedmetadata=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">\u0412 JavaScript:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nobject.onloadedmetadata = function(){myScript};\r\n<\/pre>\n<p style=\"text-align: justify;\">In JavaScript, use the method addEventListener():<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nobject.addEventListener(&quot;loadedmetadata&quot;, myScript);\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onloadstart<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 start loading the element. Handler for the loadstart event, which occurs when the process of loading an audio\/video file begins.<\/p>\n<h2><span style=\"color: #008000;\">onmessage<\/span><\/h2>\n<p style=\"text-align: justify;\">&#8211; message appears. The onmessage event occurs when a message is received through an event source. The event object for the onmessage event supports the following properties:<br \/>\ndata &#8211; Contains the actual message<br \/>\norigin \u2014 URL of the document that raised the event.<br \/>\nLastEventId \u2014 ID of the last message seen in the event stream.<br \/>\nRelated events:<br \/>\nonopen &#8211; occurs when a connection to the server is open.<br \/>\nonerror &#8211; Occurs when a problem occurs<\/p>\n<p style=\"text-align: justify;\">Create a new EventSource object and specify the URL of the page that sends the updates. Every time an update is received, the onmessage event occurs. When the onmessage event occurs, place the received data in a div element with id=&#8221;myDIV&#8221;:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar source = new EventSource(&quot;demo_sse.php&quot;);\r\nsource.onmessage = function(event) {\r\n  document.getElementById(&quot;myDIV&quot;).innerHTML += event.data + &quot;&lt;br&gt;&quot;;\r\n};\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onmousedown<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 mouse button is pressed. Handler for the mousedown event, which occurs when the left mouse button is pressed. The difference with the click event is that click is a combination of the mousedown and mouseup events. Executes JavaScript code when the MouseDown event occurs; that is, when the user presses a mouse key. If onMouseDown returns false, the default action (entering drag mode, entering selection mode, or activating a hyperlink) is canceled. Activation is triggered by the MouseDown event on the hyperlink. If the link is activated, it changes color to indicate the new state. Default action varies: initiate drag, text selection, scroll or zoom (combined with wheel press when supported)<\/p>\n<p style=\"text-align: justify;\">The onmousedown event occurs when the user presses the mouse button over an HTML element. Order of events for left and middle mouse button:<br \/>\nonmousedown<br \/>\nonmouseup<br \/>\non click<br \/>\nOrder of events for the right mouse button:<br \/>\nonmousedown<br \/>\nonmouseup<br \/>\noncontextmenu<\/p>\n<p style=\"text-align: justify;\">type &#8211;  Indicates the event type.<br \/>\ntarget &#8211; Indicates the object to which the event was originally sent.<br \/>\nlayerX, layerY, pageX, pageY, screenX, screenY- The location of the cursor when the MouseDown event occurs.<br \/>\nwhich &#8211; Represents 1 for a left mouse click and 3 for a right mouse click.<br \/>\nmodifiers &#8211; Contains a list of modifier keys pressed when the MouseDown event occurred.<\/p>\n<p style=\"text-align: justify;\">Call a function when the mouse button is pressed over a paragraph:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;p onmousedown=&quot;myFunction()&quot;&gt;Click the text!&lt;\/p&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Here the user can move the image on the HTML page by dragging it with the mouse. Your HTML code defines an image and positions it in a layer called container1. In the JavaScript code, event handlers set the positioning properties of container1 when the user drags the image, creating an animation. The ID attribute of the P element that contains the image is set to container1, making container1 a unique identifier for the paragraph and the image. The STYLE tag creates a layer for container1 and positions it. The JavaScript code below defines the onMouseDown, onMouseUp, and onMouseMove handlers. Using style sheets, the image is initially defined and positioned like this:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;HEAD&gt;\r\n&lt;STYLE type=&quot;text\/css&quot;&gt;\r\n   #container1 {\r\nposition:absolute; left:200; top:200}\r\n&lt;\/STYLE&gt;\r\n&lt;\/HEAD&gt;\r\n&lt;BODY&gt;\r\n&lt;P ID=&quot;container1&quot;&gt;\r\n&lt;img src=&quot;backgrnd.gif&quot; name=&quot;myImage&quot; width=96 height=96&gt;\r\n&lt;\/P&gt;\r\n&lt;\/BODY&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">In this code, the captureEvents method captures the MouseUp and MouseDown events. The DRAG_begindrag and DRAG_enddrag functions are called respectively to handle these events. If the user presses the left mouse button, the DRAG_begindrag function starts, capturing MouseMove events and telling the DRAG_drag function to handle them. It then assigns the value of the pageX property of the MouseDown event to the DRAG_lastX property, the value of the pageY property to the DRAG_lastY property, and true to the DRAG_dragging property. The DRAG_drag function evaluates DRAG_dragging to ensure that the MouseMove event was captured by the DRAG_begindrag function, then uses the moveBy method to position the object and assigns values \u200b\u200bto the DRAG_lastX and DRAG_lastY properties. When the user releases the left mouse button, the DRAG_enddrag function stops capturing MouseMove events. DRAG_enddrag then ensures that no other functions are called by setting onmousemove to Null and DRAG_dragging to false.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;SCRIPT&gt;\r\ncontainer1.captureEvents(Event.MOUSEUP|Event.MOUSEDOWN);\r\ncontainer1.onmousedown=DRAG_begindrag;\r\ncontainer1.onmouseup=DRAG_enddrag;\r\nvar DRAG_lastX, DRAG_lastY, DRAG_dragging;\r\nfunction DRAG_begindrag(e) {\r\nif (e.which == 1) {\r\nwindow.captureEvents(Event.MOUSEMOVE);\r\n      window.onmousemove=DRAG_drag;\r\nDRAG_lastX=e.pageX;\r\nDRAG_lastY=e.pageY;\r\nDRAG_dragging=true;\r\nreturn false;\r\n}\r\nelse {\r\n\/*Here's some work on handling right mouse clicks*\/\r\nreturn true;\r\n}\r\n}\r\nfunction DRAG_enddrag(e) {\r\nif (e.which == 1) {\r\nwindow.releaseEvents(Event.MOUSEMOVE);\r\n      window.onmousemove=null\r\nDRAG_dragging=false;\r\nreturn false;\r\n}\r\nelse {\r\n\/*Here's some work on handling right mouse clicks*\/\r\nreturn true;\r\n}\r\n}\r\nfunction DRAG_drag(e) {\r\nif (DRAG_dragging) {\r\n\/*This function is only called if MOUSEMOVE is captured*\/\r\nmoveBy(e.pageX-DRAG_lastX, e.pageY-DRAG_lastY);\r\nDRAG_lastX = e.pageX;\r\nDRAG_lastY = e.pageY;\r\nreturn false;\r\n}\r\nelse {\r\nreturn true;\r\n}\r\n}\r\n&lt;\/SCRIPT&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onmouseenter<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 The mouse pointer is over an element. A handler for the mouseenter event, which occurs when the mouse cursor enters the element&#8217;s area. Unlike mouseover, the mouseenter event does not bubble (&#8220;bubble&#8221;), that is, it does not occur if the mouse cursor hits a child element of the specified element. The onmouseenter event occurs when the mouse pointer enters an element. The onmouseenter event is often used in conjunction with the onmouseleave event, which occurs when the mouse pointer leaves an element. The onmouseenter event is similar to the onmouseover event. The difference is that the onmouseenter event does not bubble up (does not propagate up the document hierarchy).<\/p>\n<p style=\"text-align: justify;\">One mouseenter event is sent to each element of the hierarchy as they enter. Here 4 events are sent to the four elements of the hierarchy when the pointer reaches the text. A single mouseover event is sent to the deepest element of the DOM tree, then it bubbles up in the hierarchy until it is canceled by a handler or reaches the root. When there is a deep hierarchy, the number of mouseover events sent can be quite large and cause significant performance issues. In such cases, it is better to handle mouseenter events. When combined with the corresponding mouseleave event (which fires on an element when the mouse leaves the content area), the mouseenter event acts very similar to the CSS pseudo-class :hover.<\/p>\n<p style=\"text-align: justify;\">Call a function when you hover over an image:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;img onmouseenter=&quot;bigImg(this)&quot; src=&quot;smiley.gif&quot; alt=&quot;Smiley&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">JavaScript:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nobject.onmouseenter = function(){myScript};\r\nJavaScript, using the addEventListener() method:\r\nobject.addEventListener(&quot;mouseenter&quot;, myScript);\r\n<\/pre>\n<p style=\"text-align: justify;\">This example demonstrates the difference between the onmousemove, onmouseenter and mouseover events:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;div onmousemove=&quot;myMoveFunction()&quot;&gt;\r\n  &lt;p id=&quot;demo1&quot;&gt;I will demonstrate onmousemove!&lt;\/p&gt;\r\n&lt;\/div&gt;\r\n&lt;div onmouseenter=&quot;myEnterFunction()&quot;&gt;\r\n  &lt;p id=&quot;demo2&quot;&gt;I will demonstrate onmouseenter!&lt;\/p&gt;\r\n&lt;\/div&gt;\r\n&lt;div onmouseover=&quot;myOverFunction()&quot;&gt;\r\n  &lt;p id=&quot;demo3&quot;&gt;I will demonstrate onmouseover!&lt;\/p&gt;\r\n&lt;\/div&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">The following trivial example uses the mouseenter event to change the border of a div element when the mouse enters its allocated space. It then adds an element to the list with event number mouseenter or mouseleave.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;SCRIPT&gt;\r\nvar enterEventCount = 0;\r\nvar leaveEventCount = 0;\r\nconst mouseTarget = document.getElementById(&quot;mouseTarget&quot;);\r\nconst unorderedList = document.getElementById(&quot;unorderedList&quot;);\r\nmouseTarget.addEventListener(&quot;mouseenter&quot;, (e) =&gt; {\r\n  mouseTarget.style.border = &quot;5px dotted orange&quot;;\r\n  enterEventCount++;\r\n  addListItem(&quot;This is mouseenter event &quot; + enterEventCount + &quot;.&quot;);\r\n});\r\nmouseTarget.addEventListener(&quot;mouseleave&quot;, (e) =&gt; {\r\n  mouseTarget.style.border = &quot;1px solid #333&quot;;\r\n  leaveEventCount++;\r\n  addListItem(&quot;This is mouseleave event &quot; + leaveEventCount + &quot;.&quot;);\r\n});\r\nfunction addListItem(text) {\r\n\/\/ Create a new text node using the provided text\r\n  var newTextNode = document.createTextNode(text);\r\n  \/\/ Create a new li element\r\n  var newListItem = document.createElement(&quot;li&quot;);\r\n  \/\/ Add a text node to the li element\r\n  newListItem.appendChild(newTextNode);\r\n  \/\/ Add the newly created list item to the list\r\n  unorderedList.appendChild(newListItem);\r\n}\r\n&lt;SCRIPT&gt;\r\n&lt;style&gt;\r\n#mouseTarget {\r\n  box-sizing: border-box;\r\n  width: 15rem;\r\n  border: 1px solid #333;\r\n}\r\n&lt;\/style&gt;\r\n&lt;div id=&quot;mouseTarget&quot;&gt;\r\n  &lt;ul id=&quot;unorderedList&quot;&gt;\r\n    &lt;li&gt;No events yet!&lt;\/li&gt;\r\n  &lt;\/ul&gt;\r\n&lt;\/div&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onmouseleave<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 the mouse pointer has left the element. A handler for the mouseleave event, which occurs when the mouse cursor leaves the element&#8217;s area. Unlike mouseout, the mouseenter event does not bubble (&#8220;bubble&#8221;), that is, it does not occur if the mouse cursor hits a child element of the specified element. The onmouseleave event occurs when the mouse pointer leaves the element. The onmouseleave event is often used in conjunction with the onmouseenter event, which occurs when the mouse pointer enters an element. The onmouseleave event is similar to the onmouseout event. The difference is that the onmouseleave event does not bubble up (does not propagate up the document hierarchy).<\/p>\n<p style=\"text-align: justify;\">The mouseleave event fires when the cursor of a manipulator (usually a mouse) moves outside the bounds of an element. mouseleave and mouseout are similar, but differ in that mouseleave does not pop up, while mouseout does. This means that mouseleave fires when the cursor leaves the bounds of an element and all of its children, while mouseout fires when the cursor leaves the bounds of an element or one of its children (even if the cursor is still within the element).<\/p>\n<p style=\"text-align: justify;\">Call a function when the mouse pointer moves outside the image:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;img onmouseleave=&quot;normalImg(this)&quot; src=&quot;smiley.gif&quot; alt=&quot;Smiley&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">JavaScript:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nobject.onmouseleave = function(){myScript};\r\nJavaScript, using the addEventListener() method:\r\nobject.addEventListener(&quot;mouseleave&quot;, myScript);\r\n<\/pre>\n<p style=\"text-align: justify;\">This example demonstrates the difference between the onmousemove, onmouseleave and onmouseout events:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;div onmousemove=&quot;myMoveFunction()&quot;&gt;\r\n  &lt;p id=&quot;demo1&quot;&gt;I will demonstrate onmousemove!&lt;\/p&gt;\r\n&lt;\/div&gt;\r\n&lt;div onmouseleave=&quot;myLeaveFunction()&quot;&gt;\r\n  &lt;p id=&quot;demo2&quot;&gt;I will demonstrate onmouseleave!&lt;\/p&gt;\r\n&lt;\/div&gt;\r\n&lt;div onmouseout=&quot;myOutFunction()&quot;&gt;\r\n  &lt;p id=&quot;demo3&quot;&gt;I will demonstrate onmouseout!&lt;\/p&gt;\r\n&lt;\/div&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">The mouseout documentation has an example illustrating the difference between mouseout and mouseleave. The following example shows how to use mouseout to simulate the delegation principle of the mouseleave event.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;ul id=&quot;test&quot;&gt;\r\n  &lt;li&gt;\r\n    &lt;ul class=&quot;leave-sensitive&quot;&gt;\r\n      &lt;li&gt;item 1-1&lt;\/li&gt;\r\n      &lt;li&gt;item 1-2&lt;\/li&gt;\r\n    &lt;\/ul&gt;\r\n  &lt;\/li&gt;\r\n  &lt;li&gt;\r\n    &lt;ul class=&quot;leave-sensitive&quot;&gt;\r\n      &lt;li&gt;item 2-1&lt;\/li&gt;\r\n      &lt;li&gt;item 2-2&lt;\/li&gt;\r\n    &lt;\/ul&gt;\r\n  &lt;\/li&gt;\r\n&lt;\/ul&gt;\r\n&lt;script&gt;\r\n  var delegationSelector = &quot;.leave-sensitive&quot;;\r\n  document.getElementById(&quot;test&quot;).addEventListener(\r\n    &quot;mouseout&quot;,\r\n    function (event) {\r\n      var target = event.target,\r\n        related = event.relatedTarget,\r\n        match;\r\n      \/\/ search for a parent node matching the delegation selector\r\n      while (\r\n        target &amp;&amp;\r\n        target != document &amp;&amp;\r\n        !(match = matches(target, delegationSelector))\r\n      ) {\r\n        target = target.parentNode;\r\n      }\r\n\r\n      \/\/ exit if no matching node has been found\r\n      if (!match) {\r\n        return;\r\n      }\r\n      \/\/ loop through the parent of the related target to make sure that it's not a child of the target\r\n      while (related &amp;&amp; related != target &amp;&amp; related != document) {\r\n        related = related.parentNode;\r\n      }\r\n      \/\/ exit if this is the case\r\n      if (related == target) {\r\n        return;\r\n      }\r\n      \/\/ the &quot;delegated mouseleave&quot; handler can now be executed\r\n      \/\/ change the color of the text\r\n      target.style.color = &quot;orange&quot;;\r\n      \/\/ reset the color after a small amount of time\r\n      setTimeout(function () {\r\n        target.style.color = &quot;&quot;;\r\n      }, 500);\r\n    },\r\n    false,\r\n  );\r\n  \/\/ function used to check if a DOM element matches a given selector\r\n  \/\/ the following code can be replaced by this IE8 compatible function: https:\/\/gist.github.com\/2851541\r\n  function matches(elem, selector) {\r\n    \/\/ the matchesSelector is prefixed in most (if not all) browsers\r\n    return elem.matchesSelector(selector);\r\n  }\r\n&lt;\/script&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onmousemove<\/span><\/h2>\n<p style=\"text-align: justify;\">&#8211; The mouse pointer is moved over the element. Handler for the mousemove event, which occurs when the mouse pointer moves over an element.<br \/>\ntype &#8211; Indicates the event type.<br \/>\ntarget &#8211; Indicates the object to which the event was originally sent.<br \/>\nlayerX, layerY, pageX, pageY, screenX, screenY &#8211; The location of the cursor at the moment the MouseMove event occurs.<\/p>\n<p style=\"text-align: justify;\">JavaScript:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nobject.onmousemove = function(){myScript};\r\nJavaScript, using the addEventListener() method:\r\nobject.addEventListener(&quot;mousemove&quot;, myScript);\r\n<\/pre>\n<p style=\"text-align: justify;\">Call a function when you hover over a div element:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;div onmousemove=&quot;myFunction()&quot;&gt;Move the cursor over me&lt;\/div&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">The following example uses the mousedown, mousemove, and mouseup events to allow the user to draw on the HTML canvas. Its functionality is simple: the line thickness is set to 1 and the color is always black. When the page loads, the constants myPics and context are created to store a reference to the canvas and 2D context that we will use for drawing. Drawing begins when the mousedown event fires. We first store the x and y coordinates of the mouse pointer in x and y variables and then set isDrawing to true. When the mouse pointer moves across the page, the mousemove event is fired. If isDrawing is true, the event handler calls the drawLine function to draw a line from the stored x and y values \u200b\u200bto the current location. When the drawLine() function returns, we adjust the coordinates and then store them in x and y coordinates. The mouseup event draws the last line segment, sets x and y to 0, and stops further drawing by setting isDrawing to false.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;script&gt;\r\n\/\/ When true, moving the mouse draws on the canvas\r\nlet isDrawing = false;\r\nlet x = 0;\r\nlet y = 0;\r\nconst myPics = document.getElementById(&quot;myPics&quot;);\r\nconst context = myPics.getContext(&quot;2d&quot;);\r\n\/\/ event.offsetX, event.offsetY gives the (x,y) offset from the edge of the canvas.\r\n\/\/ Add the event listeners for mousedown, mousemove, and mouseup\r\nmyPics.addEventListener(&quot;mousedown&quot;, (e) =&gt; {\r\n  x = e.offsetX;\r\n  y = e.offsetY;\r\n  isDrawing = true;\r\n});\r\nmyPics.addEventListener(&quot;mousemove&quot;, (e) =&gt; {\r\n  if (isDrawing) {\r\n    drawLine(context, x, y, e.offsetX, e.offsetY);\r\n    x = e.offsetX;\r\n    y = e.offsetY;\r\n  }\r\n});\r\nwindow.addEventListener(&quot;mouseup&quot;, (e) =&gt; {\r\n  if (isDrawing) {\r\n    drawLine(context, x, y, e.offsetX, e.offsetY);\r\n    x = 0;\r\n    y = 0;\r\n    isDrawing = false;\r\n  }\r\n});\r\nfunction drawLine(context, x1, y1, x2, y2) {\r\n  context.beginPath();\r\n  context.strokeStyle = &quot;black&quot;;\r\n  context.lineWidth = 1;\r\n  context.moveTo(x1, y1);\r\n  context.lineTo(x2, y2);\r\n  context.stroke();\r\n  context.closePath();\r\n}\r\n&lt;\/script&gt;\r\n&lt;style&gt;\r\ncanvas {\r\n  border: 1px solid black;\r\n  width: 560px;\r\n  height: 360px;\r\n}\r\n&lt;\/style&gt;\r\n&lt;h1&gt;Drawing with mouse events&lt;\/h1&gt;\r\n&lt;canvas id=&quot;myPics&quot; width=&quot;560&quot; height=&quot;360&quot;&gt;&lt;\/canvas&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onmouseout<\/span><\/h2>\n<p style=\"text-align: justify;\">&#8211; the mouse pointer moves out of the element. A handler for the mouseout event, which occurs when the mouse pointer moves outside the bounds of an element. Executes JavaScript code when the MouseOut event occurs; that is, each time the mouse pointer leaves the area (in the client image map) or hyperlink. If the mouse pointer moves from one area of \u200b\u200bthe client image map to another, you will first receive onMouseOut for the first area, and then onMouseOver for the second area. Area tags that use onMouseOut are required to have an HREF attribute in the AREA tag. You must return true in the event handler if you want to set the status or defaultStatus properties using onMouseOver.<\/p>\n<p style=\"text-align: justify;\">The onmouseout event occurs when the mouse pointer moves outside of an element. The onmouseout event is often used in conjunction with the onmouseover event, which occurs when you hover over an element. The onmouseout event is similar to the onmouseleave event. The difference is that the onmouseleave event does not bubble up (does not propagate up the document hierarchy). <\/p>\n<p style=\"text-align: justify;\">type &#8211; Indicates the event type.<br \/>\ntarget &#8211; Indicates the object to which the event was originally sent.<br \/>\nlayerX, layerY, pageX, pageY, screenX, screenY &#8211; The location of the cursor at the moment the MouseOut event occurs<\/p>\n<p style=\"text-align: justify;\">Call a function when the mouse pointer moves outside the image:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;img onmouseout=&quot;normalImg(this)&quot; src=&quot;smiley.gif&quot; alt=&quot;Smiley&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">The following example illustrates the difference between the mouseout and mouseleave events. The mouseleave event is added to the ul to color the list purple whenever the mouse leaves the ul. mouseout is added to the list to color the target element orange when the mouse leaves it. When you try this you will find that mouseout is sent to individual list items and mouseleave is sent to the entire list, thanks to the element hierarchy and the fact that list items hide the base ul.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;script&gt;\r\nconst test = document.getElementById(&quot;test&quot;);\r\n\/\/ Briefly make the list purple when the mouse moves off the\r\n\/\/ &lt;ul&gt; element\r\ntest.addEventListener(\r\n  &quot;mouseleave&quot;,\r\n  (event) =&gt; {\r\n    \/\/ highlight the mouseleave target\r\n    event.target.style.color = &quot;purple&quot;;\r\n\r\n    \/\/ reset the color after a short delay\r\n    setTimeout(() =&gt; {\r\n      event.target.style.color = &quot;&quot;;\r\n    }, 1000);\r\n  },\r\n  false,\r\n);\r\n\/\/ Briefly make an &lt;li&gt; orange when the mouse moves off of it\r\ntest.addEventListener(\r\n  &quot;mouseout&quot;,\r\n  (event) =&gt; {\r\n    \/\/ highlight the mouseout target\r\n    event.target.style.color = &quot;orange&quot;;\r\n\r\n    \/\/ reset the color after a short delay\r\n    setTimeout(() =&gt; {\r\n      event.target.style.color = &quot;&quot;;\r\n    }, 500);\r\n  },\r\n  false,\r\n);\r\n&lt;\/script&gt;\r\n&lt;ul id=&quot;test&quot;&gt;\r\n  &lt;li&gt;item 1&lt;\/li&gt;\r\n  &lt;li&gt;item 2&lt;\/li&gt;\r\n  &lt;li&gt;item 3&lt;\/li&gt;\r\n&lt;\/ul&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onmouseover<\/span><\/h2>\n<p style=\"text-align: justify;\">&#8211; The mouse pointer moves over the element. A handler for the mouseover event, which occurs when the mouse cursor is hovered over an element. The onmouseover event occurs when the mouse pointer enters an element. The onmouseover event is often used in conjunction with the onmouseout event, which occurs when the mouse pointer leaves an element. The onmouseover event is similar to the onmouseenter event. The difference is that the onmouseenter event does not bubble up (does not propagate up the document hierarchy). The mouseover event is raised on an element when a pointing device (such as a mouse or trackpad) is used to move the cursor over the element or one of its children.<\/p>\n<p style=\"text-align: justify;\">Call a function when you hover over an image:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;img onmouseover=&quot;bigImg(this)&quot; src=&quot;smiley.gif&quot; alt=&quot;Smiley&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">By default, the HREF value of an anchor is displayed in the status bar at the bottom of the browser when the user hovers the mouse over the anchor. In the following example, onMouseOver displays a special message &#8220;Click this if you dare.&#8221;<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;A HREF=&quot;http:\/\/home.netscape.com\/&quot; onMouseOver=&quot;window.status='Click this if you dare!'; return true&quot;&gt;Click me&lt;\/A&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onmouseup<\/span><\/h2>\n<p style=\"text-align: justify;\">&#8211; the mouse button is released over the element. A handler for the mouseup event, which occurs when the mouse button on an element is released. If onMouseUp returns false, the default promotion is cancelled. For example, if onMouseUp returns false when a hyperlink is active, the link is not included. So, if MouseUp occurs when the hyperlink is inactive (perhaps in the case where onMouseDown returns false), the link is not included. Activation is caused by the MouseDown event on the link. If the link is active, it changes color to reflect the new state. The onmouseup event occurs when the mouse button is released over an element.<\/p>\n<p style=\"text-align: justify;\">The mouseup event is raised on an element when a button on a pointing device (such as a mouse or trackpad) is released while the pointer is inside it. Mouseup events are the opposite of mousedown events.<\/p>\n<p style=\"text-align: justify;\">Order of events for the left and middle mouse buttons:<br \/>\nonmousedown<br \/>\nonmouseup<br \/>\non click<br \/>\nOrder of events for the right mouse button:<br \/>\nonmousedown<br \/>\nonmouseup<br \/>\noncontextmenu<\/p>\n<p style=\"text-align: justify;\">type &#8211; Indicates the event type.<br \/>\ntarget &#8211; Indicates the object to which the event was originally sent.<br \/>\nlayerX, layerY, pageX, pageY, screenX, screenY &#8211; The location of the cursor at the moment the MouseUp event occurs.<br \/>\nwhich &#8211; Represents 1 for the left key and 3 for the right mouse key.<br \/>\nmodifiers &#8211; Contains a list of modifier keys pressed when the MouseUp event occurred.<\/p>\n<p style=\"text-align: justify;\">Call a function when the mouse button is released over a paragraph:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;p onmouseup=&quot;mouseUp()&quot;&gt;Click the text!&lt;\/p&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onmousewheel (onwheel)<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 the mouse wheel is used. A handler for the wheel event, which occurs when the mouse wheel is scrolled forward or backward on an element. The onwheel event occurs when the mouse wheel is hovered over an element. The onwheel event also occurs when the user scrolls the page using the touchpad. This event replaces the non-standard deprecated mouse wheel event. Don&#8217;t confuse the wheel event with the scroll event. The wheel event does not necessarily dispatch a scroll event. For example, the element may not be scrollable at all. Zoom actions using the wheel or trackpad also trigger wheel events. The scroll event is not necessarily fired by the wheel event. Elements can also be scrolled using the keyboard, dragging the scroll bar, or using JavaScript.<\/p>\n<p style=\"text-align: justify;\">Even if the wheel event triggers scrolling, the delta* values \u200b\u200bin the wheel event do not necessarily reflect the direction in which the content is scrolling. Therefore, do not rely on the delta* properties of the wheel event to get the scroll direction. Instead, detect changes in the target&#8217;s ScrollLeft and ScrollTop values \u200b\u200bin the scroll event.<\/p>\n<p style=\"text-align: justify;\">The Wheel event can be canceled. If the event is canceled, no scrolling or zooming occurs. This can cause performance issues because the browser has to wait for each wheel event to be processed before actually scrolling the content. This can be avoided by setting passive: true when calling addEventListener(), which may cause the browser to generate non-cancellable wheel events.<\/p>\n<p style=\"text-align: justify;\">When the user scrolls the mouse wheel over a div element, change its font size:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\ndocument.getElementById(&quot;myDIV&quot;).addEventListener(&quot;wheel&quot;, myFunction);\r\nfunction myFunction() {\r\n  this.style.fontSize = &quot;35px&quot;;\r\n}\r\n<\/pre>\n<p style=\"text-align: justify;\">This example shows how to scale an element using the mouse wheel (or other pointing device).<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;script&gt;\r\nfunction zoom(event) {\r\n  event.preventDefault();\r\n  scale += event.deltaY * -0.01;\r\n  \/\/ Restrict scale\r\n  scale = Math.min(Math.max(0.125, scale), 4);\r\n\r\n  \/\/ Apply scale transform\r\n  el.style.transform = `scale(${scale})`;\r\n}\r\nlet scale = 1;\r\nconst el = document.querySelector(&quot;div&quot;);\r\nel.onwheel = zoom;\r\n&lt;\/script&gt;\r\n&lt;style&gt;\r\nbody {\r\n  min-height: 100vh;\r\n  margin: 0;\r\n  display: flex;\r\n  align-items: center;\r\n  justify-content: center;\r\n}\r\ndiv {\r\n  width: 105px;\r\n  height: 105px;\r\n  background: #cdf;\r\n  padding: 5px;\r\n}\r\n&lt;\/style&gt;\r\n&lt;div&gt;Scale me with your mouse wheel.&lt;\/div&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onoffline<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 the browser is running in offline mode. The onoffline event occurs when the browser goes offline. The onoffline event is the opposite of the ononline event.<\/p>\n<p style=\"text-align: justify;\">Call the function when the browser goes offline:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;body onoffline=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">ononline<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 the browser is launched in online mode. The ononline event occurs when the browser starts going online. An online event is the opposite of an onoffline event.<\/p>\n<p style=\"text-align: justify;\">Call the function when the browser starts online:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;body ononline=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onpagehide<\/span><\/h2>\n<p style=\"text-align: justify;\">&#8211; the user navigates away from the page. The onpagehide event occurs when the user leaves a web page. There are several ways to navigate away from a page. For example. by clicking on a link, refreshing the page, submitting a form, closing the browser window, etc. The onpagehide event is sometimes used instead of the onunload event because the onunload event causes the page to not be cached. To find out whether a page is loaded directly from the server or is cached, you can use the persisted property of the PageTransitionEvent object. This property returns true if the page is cached by the browser, false otherwise.<\/p>\n\n<p style=\"text-align: justify;\">Call the function when the user navigates away from the web page:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;body onpagehide=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onpageshow<\/span><\/h2>\n<p style=\"text-align: justify;\">&#8211; the user navigates to the page. The onpageshow event occurs when the user navigates to a web page. The onpageshow event is similar to the onload event, except that it occurs after the onload event when the page is first loaded. Additionally, the onpageshow event occurs every time the page is loaded, whereas the onload event does not occur when the page is loaded from the cache. To find out whether a page is loaded directly from the server or is cached, you can use the persisted property of the PageTransitionEvent object. This property returns true if the page is cached by the browser, false otherwise<\/p>\n<p style=\"text-align: justify;\">Call the function when the user navigates to the web page:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;body onpageshow=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onpaste<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 Content has been inserted. The onpaste event occurs when the user pastes some content into an element. The onpaste event is most often used for input elements with type=&#8221;text&#8221;. The Clipboard API paste event is fired when the user initiates a &#8220;paste&#8221; action through the browser UI. If the cursor is in an editable context (for example, a textarea or an element with the contenteditable attribute set to true), then the default action is to paste the contents of the clipboard into the document at the cursor position. A handler for this event can access the contents of the clipboard by calling the getData() method on the clipboardData property of the event. To override the default behavior (for example, to paste different data or convert the contents of the clipboard), the event handler must override the default action using event.preventDefault() and then manually insert the desired data. You can create and dispatch a synthetic insert event, but this will not affect the content of the document. This event pops up, can be canceled and is composed. Used only for input fields.<\/p>\n<p style=\"text-align: justify;\">Call the function when text is inserted into an input element:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;text&quot; onpaste=&quot;myFunction()&quot; value=&quot;Paste something here&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Call the function when text is inserted into the p element. (Note that contenteditable is set to &#8220;true&#8221;):<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;p contenteditable=&quot;true&quot; onpaste=&quot;myFunction()&quot;&gt;Try to paste something inside this paragraph.&lt;\/p&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Example<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;script&gt;\r\nconst target = document.querySelector(&quot;div.target&quot;);\r\ntarget.addEventListener(&quot;paste&quot;, (event) =&gt; {\r\n  event.preventDefault();\r\n  let paste = (event.clipboardData || window.clipboardData).getData(&quot;text&quot;);\r\n  paste = paste.toUpperCase();\r\n  const selection = window.getSelection();\r\n  if (!selection.rangeCount) return;\r\n  selection.deleteFromDocument();\r\n  selection.getRangeAt(0).insertNode(document.createTextNode(paste));\r\n  selection.collapseToEnd();\r\n});\r\n&lt;script&gt;\r\n&lt;div class=&quot;source&quot; contenteditable=&quot;true&quot;&gt;Copy text from this box.&lt;\/div&gt;\r\n&lt;div class=&quot;target&quot; contenteditable=&quot;true&quot;&gt;And paste it into this one.&lt;\/div&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onpause<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 pause playback. A handler for the pause event, which occurs when audio\/video playback is paused by the user or software. The onpause event occurs when the audio\/video is paused. The onpause event also occurs when the audio\/video has reached the end.<\/p>\n<p style=\"text-align: justify;\">Call a function when the video has been paused:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;video onpause=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onplay<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 start playback. Handler for the play event, which occurs when playback of an audio\/video file has been started.<\/p>\n<p style=\"text-align: justify;\">Call the function when the video starts playing:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;video onplay=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onplaying<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 file playback. Handler for the playing event, which occurs when playback of an audio\/video file has started. The onplaying event occurs when audio\/video playback begins. The onplaying event also occurs when audio\/video resumes after being paused or buffered.<\/p>\n<p style=\"text-align: justify;\">Call a function when the video starts:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;video onplaying=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onprogress<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 getting file metadata. A handler for the progress event, which occurs when the specified audio\/video file is downloaded from the server. The onprogress event occurs when the browser loads audio or video.<\/p>\n<p style=\"text-align: justify;\">Call a function when loading a video:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;video onprogress=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onratechange<\/span><\/h2>\n<p style=\"text-align: justify;\">&#8211; change playback speed. A handler for the ratechange event, which occurs when the audio\/video playback speed changes (for example, when the user switches to slow or fast playback mode). The onratechange event occurs when the media playback speed changes (for example, when the user switches to slow-motion or fast-motion playback mode). This event is raised by the playbackRate property of the Audio\/Video object, which sets or returns the current playback speed of the audio\/video.<\/p>\n<p style=\"text-align: justify;\">Call a function when the video playback speed changes:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;video onratechange=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onreset<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 Data reset completed. Handler for the reset event, which occurs when the form is cleared when the Reset button is clicked. Executes JavaScript code when the reset event occurs; that is, when the user restores the values \u200b\u200bof form elements (by clicking the Reset button).<\/p>\n<p style=\"text-align: justify;\">Call a function when the form is reset:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;form onreset=&quot;myFunction()&quot;&gt;\r\n  Enter name: &lt;input type=&quot;text&quot;&gt;\r\n  &lt;input type=&quot;reset&quot;&gt;\r\n&lt;\/form&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">The following example outputs a Text object with a default value of &#8220;CA&#8221; and a reset button. If the user enters the state abbreviation into the Text object and clicks the reset button, the original value of &#8220;CA&#8221; is restored. The form&#8217;s onReset handler displays a message indicating that the default values \u200b\u200bhave been restored.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;FORM NAME=&quot;form1&quot; onReset=&quot;alert('Defaults have been restored.')&quot;&gt;\r\nState:\r\n&lt;INPUT TYPE=&quot;text&quot; NAME=&quot;state&quot; VALUE=&quot;CA&quot; SIZE=&quot;2&quot;&gt;&lt;P&gt;\r\n&lt;INPUT TYPE=&quot;reset&quot; VALUE=&quot;Clear Form&quot; NAME=&quot;reset1&quot;&gt;\r\n&lt;\/FORM&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onresize<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 resizing an element. Executes JavaScript code when the resize event occurs; that is, when the user or script has changed the size of the window or frame. The onresize event occurs when the browser window has been resized. Tip: To get the size of an element, use the properties clientWidth, clientHeight, InnerWidth, InnerHeight, OuterWidth, OuterHeight, OffsetWidth and\/or OffsetHeight. This handler is sent after the HTML has finished rendering with the new inner window sizes. This allows elements and named anchors to be positioned so that they have their requested final size and location, image SRC properties can be restored dynamically, etc.<\/p>\n<p style=\"text-align: justify;\">Call the function when the browser window is resized:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;body onresize=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Using the addEventListener() method to attach a &#8220;resize&#8221; event to a window object.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nwindow.addEventListener(&quot;resize&quot;, myFunction);\r\n<\/pre>\n<p style=\"text-align: justify;\">Here the open_now function creates the myWin window and captures the Resize events. The onResize handler calls the alert_me function, which displays a message if the user resizes the myWin window.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction open_now(){\r\nvar myWin;\r\nmyWin=window.open(&quot;&quot;,&quot;displayWin&quot;,&quot;width=400,height=300,resizable=yes,\r\nmenubar=no,location=no,alwaysRaised=yes&quot;);\r\nvar text=&quot;&lt;html&gt;&lt;head&gt;&lt;title&gt;Test&lt;\/title&gt;&lt;\/head&gt;&quot;\r\n+&quot;&lt;body bgcolor=white&gt;&lt;h1&gt;Please resize me&lt;\/h1&gt;&lt;\/body&gt;&quot;\r\n+&quot;&lt;\/html&gt;&quot;;\r\nmyWin.document.write(text);\r\nmyWin.captureEvents(Event.RESIZE);\r\nmyWin.onresize=alert_me;\r\n}\r\nfunction alert_me(){\r\nalert(&quot;You resized me! \\nNow my outer width: &quot; + this.outerWidth +\r\n&quot;\\n and my outer height: &quot; +this.outerHeight);\r\nthis.focus();\r\n}\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onscroll<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 Scrolling the element&#8217;s contents. The onscroll event occurs when an element&#8217;s scrollbar is scrolled. Tip: Use the CSS overflow style property to create a scrollbar for an element. The scroll event fires when the element is scrolled. To determine when scrolling has completed, look at the element&#8217;s scroll event.<\/p>\n<p style=\"text-align: justify;\">Call a function when the div is scrolled:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;div onscroll=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Switch between class names at different scroll positions. When the user scrolls down 50 pixels from the top of the page, the class name &#8220;test&#8221; is added to the element (and removed when scrolling up again).<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nwindow.onscroll = function() {myFunction()};\r\nfunction myFunction() {\r\n  if (document.body.scrollTop &gt; 50 || document.documentElement.scrollTop &gt; 50) {\r\n    document.getElementById(&quot;myP&quot;).className = &quot;test&quot;;\r\n  } else {\r\n    document.getElementById(&quot;myP&quot;).className = &quot;&quot;;\r\n  }\r\n}\r\n<\/pre>\n<p style=\"text-align: justify;\">Insert an element when the user has scrolled down 350px (add a slideUp class):<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nwindow.onscroll = function() {myFunction()};\r\nfunction myFunction() {\r\n  if (document.body.scrollTop &gt; 350 || document.documentElement.scrollTop &gt; 350) {\r\n    document.getElementById(&quot;myImg&quot;).className = &quot;slideUp&quot;;\r\n  }\r\n}\r\n<\/pre>\n<p style=\"text-align: justify;\">The following example shows how to use the scroll event to detect when the user scrolls an element:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;script&gt;\r\nconst element = document.querySelector(&quot;div#scroll-box&quot;);\r\nconst output = document.querySelector(&quot;p#output&quot;);\r\nelement.addEventListener(&quot;scroll&quot;, (event) =&gt; {\r\n  output.textContent = &quot;Scroll event fired!&quot;;\r\n  setTimeout(() =&gt; {\r\n    output.textContent = &quot;Waiting on scroll events...&quot;;\r\n  }, 1000);\r\n});\r\n&lt;\/script&gt;\r\n&lt;div id=&quot;scroll-box&quot; style=&quot;overflow: scroll; height: 100px; width: 100px; float: left;&quot;&gt;\r\n  &lt;p style=&quot;height: 200px; width: 200px;&quot;&gt;Scroll me!&lt;\/p&gt;\r\n&lt;\/div&gt;\r\n&lt;p style=&quot;text-align: center;&quot; id=&quot;output&quot;&gt;Waiting on scroll events...&lt;\/p&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">The following example shows how to use the onscroll event handler property to detect when the user scrolls:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;script&gt;\r\nconst element = document.querySelector(&quot;div#scroll-box&quot;);\r\nconst output = document.querySelector(&quot;p#output&quot;);\r\nelement.onscroll = (event) =&gt; {\r\n  output.textContent = &quot;Element scroll event fired!&quot;;\r\n  setTimeout(() =&gt; {\r\n    output.textContent = &quot;Waiting on scroll events...&quot;;\r\n  }, 1000);\r\n};\r\n&lt;\/script&gt;\r\n&lt;div id=&quot;scroll-box&quot; style=&quot;overflow: scroll; height: 100px; width: 100px; float: left;&quot;&gt;\r\n  &lt;p style=&quot;height: 200px; width: 200px;&quot;&gt;Scroll me!&lt;\/p&gt;\r\n&lt;\/div&gt;\r\n&lt;p id=&quot;output&quot; style=&quot;text-align: center;&quot;&gt;Waiting on scroll events...&lt;\/p&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onsearch<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 search completed. The onsearch event occurs when the user presses the &#8220;ENTER&#8221; key or the &#8220;x&#8221; button on an input element with type=&#8221;search&#8221;.<\/p>\n<p style=\"text-align: justify;\">Call a function when submitting a search:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;search&quot; onsearch=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onseeked<\/span><\/h2>\n<p style=\"text-align: justify;\">&#8211; the search is over. Handler for the soughted event, which occurs when the user has completed moving to a new audio\/video playback position. The onseeked event occurs when the user searches for a new position in the media.<\/p>\n<p style=\"text-align: justify;\">Call the function when the user searches for a new position in the video:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;video onseeked=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">This example demonstrates the difference between an onseeking event and an onseeked event:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;video onseeking=&quot;myFunction()&quot; onseeked=&quot;mySecondFunction()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Using the currentTime property of a Video object to display the current position during playback when the user has finished moving\/moving to a new position:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/\/ Get the video element:\r\nconst video = document.getElementById(&quot;myVideo&quot;);\r\n\/\/ Attach a seeked event to the video element:\r\nvideo.addEventListener(&quot;seeked&quot;, myFunction);\r\n\/\/ Function to display the time position of the playback:\r\nfunction myFunction() {\r\ndocument.getElementById(&quot;demo&quot;).innerHTML = video.currentTime;\r\n}\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onseeking<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 search is active. Handler for the seeking event, which occurs when the user begins moving to a new audio\/video playback position. The onseeking event occurs when the user begins searching for a new position in the media.<\/p>\n<p style=\"text-align: justify;\">Call the function when the user starts moving\/moving to a new position in the video:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;video onseeking=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onselect<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 selecting some text or value. A handler for the select event, which is when the user selects some text within an element using the mouse or keyboard.  The onselect event occurs after some text is selected in an element. The onselect event is most often used for input type=&#8221;text&#8221; or textarea elements.<\/p>\n<p style=\"text-align: justify;\">Here onSelect is used on the valueField Text object to call the selectState function.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;INPUT TYPE=&quot;text&quot; VALUE=&quot;&quot; NAME=&quot;valueField&quot; onSelect=&quot;selectState()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Call a function when some text is selected:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;text&quot; onselect=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Using the select() method of an input HTML DOM text object to select some text field content. When this happens, the onselect event is fired, which triggers the alert function.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/\/ Select the contents of a text field\r\nfunction mySelectFunction() {\r\n  document.getElementById(&quot;myText&quot;).select();\r\n}\r\n\/\/ Alert some text when the text in the text field has been selected\r\nfunction myAlertFunction() {\r\n  alert(&quot;You selected some text!&quot;);\r\n}\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onshow<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 item display. A handler for the show event, which occurs when the menu element is displayed as a context menu. The onshow event occurs when a menu element is shown as a context menu. <\/p>\n\n<p style=\"text-align: justify;\">Call the function when the menu element is displayed as a context menu:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;div contextmenu=&quot;mymenu&quot;&gt;\r\n  &lt;p&gt;Right-click inside this box to see the context menu!\r\n  &lt;menu type=&quot;context&quot; id=&quot;mymenu&quot; onshow=&quot;myFunction()&quot;&gt;\r\n    &lt;menuitem label=&quot;Refresh&quot; onclick=&quot;window.location.reload();&quot;&gt;&lt;\/menuitem&gt;\r\n  &lt;\/menu&gt;\r\n&lt;\/div&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onstalled<\/span><\/h2>\n<p style=\"text-align: justify;\">&#8211; The browser is unable to obtain media data for any reason. A handler for the stalled event, which occurs when the browser tries to obtain media data, but it is not available. The onstalled event occurs when the browser attempts to retrieve unavailable media data.<\/p>\n<p style=\"text-align: justify;\">Call the function when the browser tries to retrieve unavailable media:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;video onstalled=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onsubmit<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 confirmation of submission of form data. Handler for the submit event, which occurs when the form is submitted. Executes JavaScript code when the submit event occurs; that is, when the user submits the form to the server. You can use onSubmit to prevent the form from being submitted; To do this, place a return statement that returns false in this event handler. Any other values \u200b\u200ballow the form to be submitted. If there is no return statement, the form will be submitted.<\/p>\n<p style=\"text-align: justify;\">Here onSubmit calls the validate function to calculate the data being submitted. If the data is correct, the form is submitted; otherwise the form is not submitted.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;FORM onSubmit=&quot;return validate(this)&quot;&gt;\r\n...\r\n&lt;\/FORM&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Calling a function when a form is submitted:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;form onsubmit=&quot;myFunction()&quot;&gt;\r\n  Enter name: &lt;input type=&quot;text&quot;&gt;\r\n  &lt;input type=&quot;submit&quot;&gt;\r\n&lt;\/form&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onsuspend <\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 stop metadata extraction. A handler for the suspend event, which occurs when receiving media file data stops before the full download has completed for any reason. The onsuspend event occurs when the browser does not receive media data. The onsuspend event occurs when a download is prevented or suspended.<\/p>\n<p style=\"text-align: justify;\">Call a function when the browser does not receive media data:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;video onsuspend=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">ontimeupdate<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 changing the position (time) of file playback, that is, rewinding the file. A handler for the timeupdate event, which occurs when the audio\/video playback position has changed (for example, when the user has selected a playback point much further from the current one). The ontimeupdate event occurs when the media playback time changes. The ontimeupdate event occurs while media is playing. The ontimeupdate event occurs when the user moves the playback position.<\/p>\n<p style=\"text-align: justify;\">Call the function when the playback time has changed:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;video ontimeupdate=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Using the currentTime property to set the current playback position to 5 seconds:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\ndocument.getElementById(&quot;myVideo&quot;).currentTime = 5;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">ontoggle<\/span><\/h2>\n<p style=\"text-align: justify;\">&#8211; the user opens or closes the details element Handler for the toggle event that occurs when the user opens or closes the details element. The ontoggle event occurs when the user opens or closes the details element. The details element specifies additional information that the user can view or hide upon request.<\/p>\n<p style=\"text-align: justify;\">Call a function when the details element is opened or closed:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;details ontoggle=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onunload<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 The loading is completed, after which the document is closed. The onunload event occurs after the page has unloaded (or the browser window has been closed). onunload occurs when the user navigates away from the page (by clicking a link, submitting a form, closing the browser window, etc.). Note. The onunload event is also fired when the user reloads the page (and the onload event). Use onUnload with BODY or FRAMESET tags, for example, BODY onUnload=&#8221;&#8230;&#8221;. Regarding frames and framesets, the frame&#8217;s onUnload handler (placed in the BODY tag) appears before the frameset&#8217;s onUnload handler (placed in the FRAMESET tag) appears.<\/p>\n<p style=\"text-align: justify;\">Call the function when the user unloads the document:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;body onunload=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Here onUnload calls the cleanUp function to do some finishing processing when the user exits the page (closes it):<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;BODY onUnload=&quot;cleanUp()&quot;&gt;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onvolumechange<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 volume changed. Handler for the volumechange event, which occurs when the sound volume value changes (including muting the sound completely). The onvolumechange event occurs when the media volume changes. The onvolumechange event occurs when the volume increases or decreases. The onvolumechange event occurs when audio is muted or unmuted.<\/p>\n<p style=\"text-align: justify;\">Call a function when the video volume changes:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;video onvolumechange=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n<p style=\"text-align: justify;\">Using the Volume property to set volume:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\ndocument.getElementById(&quot;myVideo&quot;).volume = 0.2;\r\n<\/pre>\n<h2><span style=\"color: #008000;\">onwaiting<\/span><\/h2>\n<p style=\"text-align: justify;\">\u2013 waiting for playback to resume. A handler for the waiting event, which occurs when a media file is stopped but is waiting to resume running (for example, when the file pauses to buffer remaining data). The onwaiting event occurs when the media must wait for the next frame.<\/p>\n<p style=\"text-align: justify;\">Call the function when the video is stopped because the next frame needs to be buffered:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;video onwaiting=&quot;myFunction()&quot;&gt;\r\n<\/pre>\n\n","protected":false},"excerpt":{"rendered":"<p>Event handlers should be used in the correct way; it is advisable not to write them directly in tag attributes, but to install event handlers in included files with JavaScript code. If the jQuery library is used, then the name of the handlers must be written without the on prefix.<\/p>\n","protected":false},"author":1,"featured_media":251,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,112,7],"tags":[126,13,125],"class_list":{"0":"post-250","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-htmlverstka","8":"category-javascript","9":"category-programmirovanie","10":"tag-events","11":"tag-html","12":"tag-javascript"},"_links":{"self":[{"href":"https:\/\/planeta21vek.ru\/elina732\/eng\/wp-json\/wp\/v2\/posts\/250","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/planeta21vek.ru\/elina732\/eng\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/planeta21vek.ru\/elina732\/eng\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/planeta21vek.ru\/elina732\/eng\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/planeta21vek.ru\/elina732\/eng\/wp-json\/wp\/v2\/comments?post=250"}],"version-history":[{"count":2,"href":"https:\/\/planeta21vek.ru\/elina732\/eng\/wp-json\/wp\/v2\/posts\/250\/revisions"}],"predecessor-version":[{"id":273,"href":"https:\/\/planeta21vek.ru\/elina732\/eng\/wp-json\/wp\/v2\/posts\/250\/revisions\/273"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/planeta21vek.ru\/elina732\/eng\/wp-json\/wp\/v2\/media\/251"}],"wp:attachment":[{"href":"https:\/\/planeta21vek.ru\/elina732\/eng\/wp-json\/wp\/v2\/media?parent=250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/planeta21vek.ru\/elina732\/eng\/wp-json\/wp\/v2\/categories?post=250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/planeta21vek.ru\/elina732\/eng\/wp-json\/wp\/v2\/tags?post=250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}