+ 17
What is inner HTML ?
I am a bit confused about DOM. I have started it learning right now. What should I do to learn it or how should I learn it?
6 Antworten
+ 5
For understanding innerHTML property you first need to go through the basics of the javascript object and HTML DOM(Document object model). I will try to explain:
1. JavaScript objects consist of properties and methods.
2. for rendering HTML document web browser creates a DOM, in DOM every HTML element is treated as a JavaScript Object which has set of properties and methods associated with it.
Now coming to your Question:
HTML code:
<p id= "myPara"> We love to Code.</p>
JavaScript code:
alert(document.getElementById("myPara").innerHTML);
here, document.getElementById("myPara") will return our html element <p> as an javascript object which has pre-defined property innerHTML.
innerHTML property contains the content of HTML tag.
Hope this will help.
You can run following HTML code in your browser or in codeplayground to understand it:
<html>
<body>
<p id= "myPara"> We love to Code.</p>
<script>
alert(document.getElementById("myPara").innerHTML);
</script>
</body>
</html>
+ 16
It returns the html content (html tags and their content) that is inside a given element. For example:
<div id="test">
<p> return me ! <p>
</div>
when you call
var el = document.querySelector("#test").innerHTML;
it'll return <p> return me !! </p>
furthermore innerHTML can similarly be used to set/change content as well
+ 14
oh.. thanks @KINGDX
+ 6
The innerHTML feature returns the content of a HTML element.
0
it is a set of HTML elements or content 🤔
0
Hi, Modifies html content.