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:

Event Handers
Triggers
onblurWhen the window loses focus
onchangeWhen an element change.
onclickOn a mouse click
ondblclickOn a mouse double-click
ondragWhen an element is dragged
ondragendAt the end of a drag operation
ondragenterWhen an element has been dragged to a VALID drop target
ondragleaveWhen an element is being dragged over a valid drop target
ondragoverAt the start of a drag operation
ondragstartAt the start of a drag operation
ondropDragged element is being dropped
ondurationchangeWhen the length of the media is changed
onerrorWhen an error occur
oninputWhen an element gets user input
oninvalidWhen an element is invalid
onkeydownWhen a key is pressed
onkeypressWhen a key is pressed and released
onkeyupWhen a key is released
onmousedownTriggers when a mouse button is pressed
onmousemoveTriggers when the mouse pointer MOVES
onmouseoutTriggers when the mouse pointer moves out of an element
onmouseoverTriggers when the mouse pointer moves over an element
onmouseupTriggers when a mouse button is released
onmousewheelTriggers 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&GT;    <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:



Discussion

No Comment Found