This function retrieves the target element of an event and allows you to create reusable JavaScript code.

Parameters:

  • event - the browser's event object

Example:

The following functions can be attached to multiple elements' onmouseover and onmouseout events to create a nice hover effect:

function mouseOver(event) {
  var target = getTarget(event);
  target.style.border = "1px dotted blue";  // apply the hover effect
}

function mouseOut(event) {
  var target = getTarget(event);
  target.style.border = "";  // remove the hover effect
}
  • No labels