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
1182
votes
14 answers

How to replace innerHTML of a div using jQuery?

How could I achieve the following: document.all.regTitle.innerHTML = 'Hello World'; Using jQuery where regTitle is my div id?
tonyf
  • 34,479
  • 49
  • 157
  • 246
332
votes
14 answers

Difference between innerText, innerHTML and value?

What is the difference between innerHTML, innerText and value in JavaScript?
user2819851
  • 3,371
  • 3
  • 12
  • 6
296
votes
5 answers

React.js: Set innerHTML vs dangerouslySetInnerHTML

Is there any "behind the scenes" difference from setting an element's innerHTML vs setting the dangerouslySetInnerHTML property on an element? Assume I'm properly sanitizing things for the sake of simplicity. Example: var test = React.createClass({ …
Jshoe523
  • 3,851
  • 2
  • 18
  • 21
286
votes
26 answers

Can scripts be inserted with innerHTML?

I tried to load some scripts into a page using innerHTML on a
. It appears that the script loads into the DOM, but it is never executed (at least in Firefox and Chrome). Is there a way to have scripts execute when inserting them with…
Craig
  • 7,471
  • 4
  • 29
  • 46
245
votes
6 answers

Append HTML to container element without innerHTML

I need a way to append HTML to a container element without using innerHTML. The reason why I do not want to use innerHTML is because when it is use like this: element.innerHTML += htmldata It works by replacing all of the html first before adding…
Bob
  • 2,453
  • 2
  • 15
  • 4
245
votes
15 answers

Show/hide 'div' using JavaScript

For a website I'm doing, I want to load one div, and hide another, then have two buttons that will toggle views between the div using JavaScript. This is my current code function replaceContentInContainer(target, source) { …
Jake Ols
  • 2,792
  • 3
  • 18
  • 29
215
votes
12 answers

Angular 2 - innerHTML styling

I am getting chunks of HTML codes from HTTP calls. I put the HTML blocks in a variable and insert it on my page with [innerHTML] but I can not style the inserted HTML block. Does anyone have any suggestion how I might achieve this? @Component({ …
Jakob Svenningsson
  • 4,175
  • 6
  • 23
  • 26
170
votes
23 answers

Executing test Problem is that the code inside the

phil crowe
  • 1,445
  • 2
  • 11
  • 15
108
votes
11 answers

How to get innerHTML of DOMNode?

What function do you use to get innerHTML of a given DOMNode in the PHP DOM implementation? Can someone give reliable solution? Of course outerHTML will do too.
Dawid Ohia
  • 16,129
  • 24
  • 81
  • 95
97
votes
10 answers

Add/remove HTML inside div using JavaScript

I want to be able to add multiple rows to a div and also removing them. I have a '+' button at the top of the page which is for adding content. Then to the right of every row there is a '-' button that's for removing that very row. I just can't…
Daniel Tovesson
  • 2,550
  • 1
  • 30
  • 41
1
2 3
99 100