Document get element by id innerhtml
ExampleGet the HTML content of an element with id="myP": Show
let html = document.getElementById("myP").innerHTML; Try it Yourself » Change the HTML content of an element with id="demo": document.getElementById("demo").innerHTML = "I have changed!"; Try it Yourself » Get the HTML content of a
let html = document.getElementById("myList").innerHTML; Try it Yourself » Delete the HTML content of a element with id="demo": element.innerHTML = ""; Try it Yourself » More examples below. Definition and UsageThe The Differences Between innerHTML, innerText and textContentSee below SyntaxReturn the innerHTML property: Set the innerHTML property: Property Value
Return Value
More ExamplesExampleChange the HTML content of two elements: let text = "Hello Dolly."; Try it Yourself » ExampleRepeat the HTML content of an element: element.innerHTML += element.innerHTML; Try it Yourself » ExampleChange the HTML content and URL of a link: element.innerHTML = "W3Schools"; Try it Yourself » The Differences Between innerHTML, innerText and textContent
|