[JAVASCRIPT] Can you help me with some codes.
Hi... Can you please help me with some Javascript codes... I'm still on the process of learning Javascript...
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test123</title>
<style type="text/css">
<!--
#main{
width:500px;
height: 20px;
background: lightblue;
}
#hidden, #hidden1 {
width:300px;
height:20px;
background: lightgrey;
display: none;
}
-->
</style>
<script language="JavaScript">
function toggle(id) {
var state = document.getElementById(id).style.display;
if (state == 'block') {
document.getElementById(id).style.display = 'none';
} else {
document.getElementById(id).style.display = 'block';
}
}
</script>
</head>
<body>
<div id="main">
This is not hidden.
<a href="#" onclick="toggle('hidden');">Click 1<br></a>
This is not hidden to.
<a href="#" onclick="toggle('hidden1');">Click 2</a>
</div>
<div id="test"
<p id="hidden">This is hidden.</p>
<p id="hidden1">This is hidden to.</p>
</div>
</body>
</html>
What this code do is when you click on Click 1 a message will show "This is hidden". And when you click on Click 2 the message "This is hidden to." will show on the bottom of the first message. What I'm trying to ask help for is a code in where when you press Click 1 or 2. will be change...
For example I'll press Click 1. And the message "This is hidden" will show... And when I press Click 2 I don't want the message on Click 2 show on the bottom of the message of click 1 but instead changing the message of Click 1 to the message of click 2.
Re: [JAVASCRIPT] Can you help me with some codes.
You can change the content of the <p> with .innerHTML
Code:
<script language="JavaScript">
function toggle(id) {
var state = document.getElementById(id).innerHTML;
if (state == 'This is hidden.') {
document.getElementById(id).innerHTML = 'This is hidden to.';
} else {
document.getElementById(id).innerHTML = 'This is hidden.';
}
}
</script>
Is that what you want?
Re: [JAVASCRIPT] Can you help me with some codes.