Rewrite Text Content on a Click

[Total: 0    Average: 0/5]

This example uses a href click to re-write the content of a text string.

Body Code:

<style>
#one {position: absolute;
      top: 40px;
	  left: 40px;
	  background-Color: #DDCCFF;
	  color: #FF0000;
	  }
</style>
<script>
/*
 * Determine the web browser type.
 */
var isNS6 = navigator.userAgent.indexOf("Gecko")!=-1? true:false;
var isNS4 = !isNS6 && document.layers ? true: false;
var isIE  = !isNS6 && document.all ? true: false;

/*
 * What is the original message to be?
 */
var _w = 'Original Content';

/*
 * These write out the original message.
 */
var _docName="one";
if (isNS4)
 _w = "<span id=one name="+_docName+">"+_w+"</span>";
if (isIE||isNS6)
 _w = "<div id=one name="+_docName+">"+_w+"</div>";
document.write(_w);


function replaceIt(_v) {
  if (isNS4) {
    eval("document."+_docName+".document.open();");
    eval("document."+_docName+".document.write('<layer id=one name=one>'+_v+'</layer>');");
    eval("document."+_docName+".document.close();");
  }
  if (isIE) {
    eval("document.all."+_docName+".innerHTML=_v;");
  }
  if (isNS6) {
    document.getElementById(_docName).innerHTML=_v;
  }
}
</script>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<a href="javascript:replaceIt('hi there')">click me</a>

Times Viewed: 1

Leave a Reply

Your email address will not be published. Required fields are marked *