JavaScript code to display text in a defined area upon click

January 2017



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


Published by aakai1056. Latest update on May 21, 2012 at 09:18 AM by aakai1056.
This document, titled "JavaScript code to display text in a defined area upon click," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).