<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11//DTD/xhtml11.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Dom demo</title>
<script type="text/javascript">
function changeText()
{
document.getElementById('first').innerHTML="Second Entry";
document.getElementById('second').innerHTML="First Entry";
}
</script>
</head>
<body>
<div id="first">First Entry</div>
<div id="second">Second Entry</div>
<input type="button" onclick="changeText()" value="Change text of this document">
</body>
</html>
views:
53answers:
1
A:
function changeText()
{
var temp;
temp = document.getElementById('first').innerHTML;
document.getElementById('first').innerHTML=document.getElementById('second').innerHTML;
document.getElementById('second').innerHTML=temp;
}
I'm not sure if that is what you wanted but that will allow you to continuously swap values between the divs.
Andrew Dunn
2010-09-19 23:03:32
A jsFiddle that does the above ==> http://jsfiddle.net/qv6s9/
Peter Ajtai
2010-09-20 00:13:05