event.relatedTargetS2C Home « Objects « event.relatedTarget

Event related target property.

Description

The event.relatedTarget Event object property, contains the value of the other DOM element, if it exists, involved in mouseoout and mouseover events.

Syntax

Signature Description
event.relatedTargetThe value of the other DOM element, if it exists, involved in mouseoout and mouseover events.

Parameters

None.

Return

A DOM element.

event.relatedTarget ExampleTop

Contains the value of the other DOM element, if it exists, involved in mouseoout and mouseover events.

In the example below when you enter or leave the 'div3' element the mouseoout and mouseover JavaScript events fire and we output the event.relatedTarget as part of the message.



$(function(){
  $('#div3').on({
     'mouseover.ns1': function(event) {
       $(this).css({backgroundColor: 'teal', color: 'black'})
              .append('**entering "div3. " Related Target: ' + event.relatedTarget.<br/ >');
     },
     'mouseout.ns2': function(event) {
       $(this).css({backgroundColor: 'blue', color: 'white'})
              .append('**leaving "div3. " Related Target: ' + event.relatedTarget.<br/ >');
     }
  });
});

div3. Some initial text.