1.

Empty an array in JavaScript

Answer»

Events handle JavaScript's interaction with HTML. Events can be related to a button being click or a web page loaded. Resizing a window also comes under event.

The following are the events. A function in JavaScript gets executed against the event:

Events
Triggers
onblur
When the window loses focus
onchange
When an element change.
onclick
On a mouse click
ondblclick
On a mouse double-click
ondrag
When an element is dragged
ondragen
At the end of a drag operation
ondragenter
When an element has been dragged to a valid drop target
ondragleave
When an element is being dragged over a valid drop target
ondragover
At the START of a drag operation
ondragstart
At the start of a drag operation
ondrop
Dragged element is being dropped
ondurationchange
When the length of the MEDIA is changed
onerror
When an error occurs
oninput
When an element gets user input
oninvalid
When an element is invalid
onkeydown
When a key is PRESSED
onkeypress
When a key is pressed and released
onkeyup
When a key is released
onmousedown
Triggers when a mouse button is pressed
onmousemove
Triggers when the mouse pointer moves
onmouseout
Triggers when the mouse pointer moves out of an element
onmouseover
Triggers when the mouse pointer moves over an element
onmouseup
Triggers when a mouse button is released
onmousewheel
Triggers when the mouse wheel is being rotated

Let us see an example of onclick event in JavaScript wherein the event gets triggered when left button of the mouse is clicked:

<html>    <head>       <script>          <!--             function show() {                alert("This is a message!")             }          //-->       </script>    </head>    <body>       <p>Click the below button:</p>       <form>          <input type="button" onclick="show()" value="Display" />       </form>    </body> </html>

The output:

Event gets triggered when you click on the button “Display” to agenerate the following alert:

Let us see another example wherein we are displaying the current date and TIME on click of a button:

<!DOCTYPE html> <html> <body> <button onclick="document.getElementById('myid').innerHTML=Date()">Time</button> <h2 id="myid"></h2> </body> </html>

The following output generates on the click of a button that we created in the example above:



Discussion

No Comment Found