InterviewSolution
| 1. |
Regular Expression in JavaScript to display non-digit characters from a string |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
Answer» Events handlers assist in 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 event handlers in JavaScript:
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 to generate 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: |
|||||||||||||||||||||||||||||||||||||||||||||||||||