Reputation: 169
I've got a feeling this is an incredibly simple operation. I could just use some steer on what exactly I am doing wrong here.
I just need a simple program to take the content from <span id "text"
> and copy this into <div id="text2">
.
function getValue() {
var text = document.getElementById("text");
document.getElementById("text2").innerHTML = text;
};
getValue;
<span id="text"> Hi there </span>
<div id="text2"></div>
Upvotes: 1
Views: 47
Reputation: 3978
Use this code:
function getValue(){
document.getElementById("text2").innerHTML = document.getElementById("text").innerHTML;
}
getValue();
This code should be in a onload function or in the body tag.
Upvotes: 2
Reputation: 1113
It seems that you are not calling function properly.
getValue();
instead of
getValue;
Upvotes: 3
Reputation: 19
try this jQuery code...
function getValue(){
$("#text2").text($("#text").text());
}
this works for me...
Upvotes: -2
Reputation: 1336
try following:
function getValue()
{
var text=document.getElementById("text").innerHTML;
document.getElementById("text2").innerHTML = text;
};
Upvotes: -1