JavaScript code to display text in a defined area upon click

December 2016


I am looking for a JavaScript code that would allow me to display text in a defined area when I click on a link.

The page in question is composed of blocks set via CSS.

In the <head> tag:
function ChangeMessage(message,champ)
    document.getElementById(champ).innerHTML = message;

and in <body> :
<A HREF="page.htm" onMouseOver="ChangeMessage('Texte','ejs_texte')" onMouseOut="ChangeMessage('','ejs_texte')">Lien</A>


To trigger action upon click, you must change the HTML event:
<a href="page.htm" onclick="ChangeMessage('Texte','ejs_texte')" >Lien</a>

Related :

This document entitled « JavaScript code to display text in a defined area upon click » from CCM ( is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.