answersLogoWhite

0

Event handling is when an action from the user triggers a JavaScript function. An event handler is defined as the following:

onclick="alert('You clicked me!');">Click me!

This will open an alert box with the message You clicked me! displayed in it when the user clicks the div element.

There are many event handlers in JavaScript. Some common ones include:

  • onclick (triggered when user clicks the element)
  • onload (triggered when page, image, etc. loads)
  • onfocus (triggered when element gains focus (becomes active))
  • onblur (triggered when element loses focus)
  • onmouseover (triggered when user's mouse pointer enters the element)
  • onmouseout (triggered when user's mouse pointer leaves the element)
  • onmousemove (triggered when user's mouse pointer is moved while it is on top of the element)
  • onkeydown (triggered when user presses a key on the keyboard)
  • onkeyup (triggered when user releases a key on the keyboard)
  • onkeypress (triggered when user presses, then releases a key on the keyboard)

I would recommend you look some of these up and find out more.

Event handlers can be applied as HTML attributes as shown above, or they can be applied during JavaScript execution, as shown below.

In Netscape-based browsers (Firefox, Google Chrome, etc.):

var myHTMLElement=document.getElementById("myElement");

myHTMLElement.onclick="You clicked me!"

Or:

var myHTMLElement=document.getElementById("myElement");

myHTMLElement.addEventListener("click",function (){alert("You clicked me!");});

Note that when using addEventListener, remove the "on" from the event name to get the first parameter. For example, "onload" becomes "load". Also, you can remove this event handler with removeEventListener using the same parameters as addEventListener.

In internet Explorer (prior to version 9):

var myHTMLElement=document.getElementById("myElement");

myHTMLElement.attachEvent("onclick",function (){alert("You clicked me!");});

In Internet Explorer 9, you can use the method you used for Netscape-based browsers. Also, you can remove this event handler with detachEvent using the same parameters as attachEvent.

I would encourage you to find out more about event handlers by searching Google.

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

What are the advantages and disadvantages event handler to event properties?

what are the advantages and dis advantages of event handling in java


What is meant by java script?

JavaScript is a scripting language that can be used with HTML or PHP. It is used for handling the control or conditioning.


What is java fx2.1.1?

Java script


Is Java script needed for Poptropica?

No, Java script is not needed to play poptropica.


Definition of event handling in java?

When an application or a program keeps on monitoring and quickly responds to any action that occurs at the GUI interface ,like mouse movement, selecting an item in a list or entering a keyboard input and so on then such a scenario is termed as event handling. In java the events from the event sources are captured and they are sent to event listeners for respective actions to be taken.


Does Java Script use the same compiler as Java?

No


Where can I download java script free?

When it comes to java script you can simply download it free from the java website. You can also go to CNET downloads and get it free from there.


Does java script coding mean using it for Java programs only?

Java script coding is computer coding, many things require Java, and you need to have Java enabled to view these types of programs.


Does iPod touches have java script?

they have java< javascript and flash


Which script based on sound?

Java script is based on sound.


How do you write a code in java script for follow the image with cursor?

<html> <head> <script language="javascript"> function f_follow(event) { temp.style.position="absolute";//this is necessary temp.style.left=event.clientX; temp.style.top=event.clientY; } </script> <body onmousemove="f_do(event)"> <img src="....." id="temp"/> </body> </html>


Do you have Java script installed on this computer?

No