I am getting a value by using document.getElementById("forloop").innerHtml
. 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?
Firstly, to get the innerHTML value of any tag, you either need that tag to have its 'id' property or 'name' property set. Then you can respectively use the 'document. getElementById(yourTagIdValue). innerHTML' or 'document.
Appending to innerHTML is not supported: Usually, += is used for appending in JavaScript. But on appending to an Html tag using innerHTML, the whole tag is re-parsed.
To set the value of innerHTML property, you use this syntax: element. innerHTML = newHTML; The setting will replace the existing content of an element with the new content.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With