View Full Version : Problem Toggling content of div tags

07-04-2007, 09:36 PM
I'm building a translation website and need to be able to toggle the content of div tags to show how a paragraph looks in each language.

I have used the following code, which works fine:

<script type="text/javascript">
function makeTxt(id,txt){
var obj = document.getElementById(id);

<a onclick="makeTxt('id1','text 1 text 1 text 1 text 1 text 1 text 1 text 1 text 1 text 1')"><img src="image.jpg">
<div id="id1">text 2 text 2 text 2 text 2 text 2 text 2 text 2 text 2 text 2 text 2 </div>

What i'd like to do is to have a "restore" button which restores the content to what it was originally.

Any ideas?

07-05-2007, 12:11 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<script language="JavaScript" type="text/javascript">

function zxcCngTxt(zxcid,zxctxt){
if (zxcdivs.length==0){
zxcES(zxcp.cloneNode(true),{position:'absolute',zIndex:'2',left:'0px',top:'0px',border:'solid black 0px'},zxcp);
zxcES(zxcp.cloneNode(false),{position:'absolute',left:'0px',top:'0px',border:'solid black 0px'},zxcp);

function zxcES(zxcele,zxcstyle,zxcp,zxctxt){
if (typeof(zxcele)=='string'){ zxcele=document.createElement(zxcele); }
for (key in zxcstyle){ zxcele.style[key]=zxcstyle[key]; }
if (zxcp){ zxcp.appendChild(zxcele); }
if (zxctxt){ zxcele.appendChild(document.createTextNode(zxctxt)); }
return zxcele;

function zxcNoTxtNodes(zxcp){
var zxcclds=zxcp.childNodes,zxcary=[];
for (var zxca=0;zxca<zxcclds.length;zxca++){ if (zxcclds[zxca].nodeType!=1) zxcary.push(zxcclds[zxca]); }
for (var zxcb=0;zxcb<zxcary.length;zxcb++){ zxcp.removeChild(zxcary[zxcb]); }
return zxcclds;

<input type="button" value="Cng Text 1" onclick="zxcCngTxt('m1','More Text');"/>
<input type="button" value="Cng Text 2" onclick="zxcCngTxt('m1','Even More Text');"/>
<input type="button" value="Original" onclick="zxcCngTxt('m1');"/>
<div id="m1" style="position:relative;width:100px;height:100px;background-Color:#FFFFCC;border:solid black 1px;" >
some Text</div>



07-05-2007, 10:20 AM
Is there a function to simply restore the original conents? That works when an image is clicked?