+ 1
innerHTML
I still don’t understand what the function of innerHTML is, can someone help me, please
4 Réponses
+ 2
.innerHTML = "<a href='https://google.com'> Google Link <\a>"
<!-- The output will be : Google Link -->
BUT When you try the .textContent = "<a href='https://google.com'> Googe Link <\a>"
<!-- The output will be : <a href='https://google.com'> Google Link <\a> -->
And the last one is .innerText for example in html file you write this
<p>
<style> p{ color: red;} <\style>
How are you?
</p>
<!-- The output will be : -->
How are you (WITH black color)
+ 2
innerHTML allows you to get or set HTML of any other element.
Like you have a div and you want to set a <b> tag inside of it :
div.innerHTML = "<b>I am bold</b>";
+ 2
innerHTML is not a function, it is a proprety only when you see this () this is the function,
like
Math.random() // this is a function and ready to use and its already stored inside the language you just called it...
function () { } // this is called a custom function and you write your codes inside it to do something different.
+ 1
The innerHTML is simply the text and elements between a start and end tag.
For example, in your html, if you will print out thr innerHTML of the body as text, you will see all the contents between the body tags.
Same goes with any other element.