JavaScript code to display text in a defined area upon click

December 2016



Issue


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:
<SCRIPT LANGUAGE="JavaScript">
function ChangeMessage(message,champ)
  {
  if(document.getElementById)
    document.getElementById(champ).innerHTML = message;
  }
</SCRIPT>



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

Solution


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 (ccm.net) 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.