InterviewSolution
| 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:
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: |
|||||||||||||||||||||||||||||||||||||||||||||||||||