Questions tagged [innerhtml]

innerHTML is a DOM node's property that gets or sets the inner HTML code of an HTML element. It is commonly used in Javascript to dynamically change or read from a page.

innerHTML is a DOM node's property that gets or sets the inner HTML code of an HTML element. It is commonly used in JavaScript to dynamically change or read from a page.

Syntax to get innerHTML

var content = element.innerHTML; /* To get the inner HTML of an element */

where,

content contains the serialized HTML code describing all of the element's descendants.

Syntax to set innerHTML

element.innerHTML = content; /* To set the inner HTML of an element */

Removes all of element's children, parses the content string and assigns the resulting nodes as children of the element.

2983 questions
37
votes
3 answers

Is there any major difference between innerHTML and using createTextNode to fill a span?

The title is pretty clear: Is there any major difference between innerHTML and createTextNode (used with Append) to fill a span with text?
Jeff Noel
  • 7,500
  • 4
  • 40
  • 66
35
votes
8 answers

How to get the height of the text inside of a textarea

I have a textarea with the the text Hello World. I would like to get the height of this text. I've tried to use: var element = document.getElementById('textarea'); var textHeight = element.innerHTML.offsetHeight; and: var textHeight =…
Adam Halasz
  • 57,421
  • 66
  • 149
  • 213
34
votes
7 answers

Does document.body.innerHTML = "" clear the web page?

When I refresh the page below in FF 3.0, I expected the web page to clear but it didn't. Why doesn't document.body.innerHTML = "" clear the page? UPDATE: I am trying to clear the previous screen during a refresh while the new page is loading. I…
Tony_Henrich
  • 42,411
  • 75
  • 239
  • 374
33
votes
6 answers

javascript innerHTML adding instead of replacing

quick question, i know we can change the content of a
hello one
by using: document.getElementById("whatEverId").innerHTML="hello two"; now, is there a way I can ADD stuff to the div instead of replacing it??? so i can get…
Gmo
  • 333
  • 1
  • 3
  • 4
31
votes
2 answers

How to correctly use innerHTML to create an element (with possible children) from a html string?

Note: I do NOT want to use any framework. The goal is just to create a function that will return an element based on an HTML string. Assume a simple HTML Document like such: All functions mentioned are…
Sanchit
  • 2,240
  • 4
  • 23
  • 34
30
votes
2 answers

Is it safe to use [innerHTML] in Angular 5?

I have seen conflicting reports that it is dangerous to use the [innerHTML] tag in Angular2+. Is that still the case or has it since been fixed? for example is this code dangerous:
ahat91
  • 546
  • 1
  • 6
  • 10
29
votes
5 answers

set innerHTML of an iframe

In javascript, how can I set the innerHTML of an iframe? I mean: how to set, not get. window["ifrm_name"].document.innerHTML= "

Hi

" does not work, and the same for other solutions. Iframe and parent document are on the same domain. I would…
tic
  • 4,009
  • 15
  • 45
  • 86
28
votes
3 answers

innerHTML without the html, just text

I've created an e-mail link that automatically populates the necessary information in the body. But, when I do .innerHTML I get a little more than I bargained for. I want "March, 2012: 12-16" What I get March, 2012: 12
cphilpot
  • 1,155
  • 3
  • 17
  • 39
25
votes
8 answers

Setting innerHTML: Why won't it update the DOM?

Wondering why I can't get document.getElementById("my_div").innerHTML to update the DOM when I re-assign the variable. For example:
Bye.
If I…
Marco Demaio
  • 33,578
  • 33
  • 128
  • 159
23
votes
5 answers

Access Contents of

This javascript snippet just returns an empty string. Is there a way of getting the contents of a…
joshwbrick
  • 5,882
  • 9
  • 48
  • 72
23
votes
10 answers

Javascript Iframe innerHTML

Does anyone know how to get the HTML out of an IFRAME I have tried several different…
Ubervan
21
votes
12 answers

Uncaught Typeerror: cannot read property 'innerHTML' of null

Can anyone explain what is this error? Uncaught TypeError: cannot read property 'innerHTML' of null This is the line which is causing the issue: var idPost=document.getElementById("status").innerHTML;
Davix Ponze
  • 219
  • 1
  • 2
  • 3
21
votes
4 answers

How to add onclick event to a string rendered by dangerouslysetInnerHtml in reactjs?

I have a string , i.e, let string= "Hello Click here"; render() { return (
} createMarkup = value => { return { __html: value }; }; What I would like is to be able to add…
PCK
  • 1,254
  • 6
  • 20
  • 37