开发者

Getting innerhtml value into the variable

I am getting a value by using document.getElementById("forloop").inne开发者_Python百科rHtml. And I am displaying that value in the file with some div id as

<div id="forloop"></div>.

But I want to assign that value to a variable in the file. Can you please how can I assign to the variable?


var myInnerHtml = document.getElementById("forloop").innerHTML;

In most browsers, the property is named innerHTML (with HTML in all-caps), not innerHtml, so watch for that.


If you want the value along with the HTML tags then you will use:

var x=document.getElementById("forloop").innerHTML;

Or if you want only the value then you will use:

var x=document.getElementById("forloop").innerText;


I'm not sure if i understand right, maybe this?

var variable = document.getElementById("forloop").innerHTML;


Don't know where the strech is:

var x = document.getElementById("forloop").innerHTML;


Is the innerHTML of <div id="forloop"></div> added through JavaScript? If so, you might want to make sure that the var myInnerHtml = document.getElementById("forloop").innerHTML gets executed after the innerHTML has been added.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜