+ 1

innerHTML

I still don’t understand what the function of innerHTML is, can someone help me, please

19th May 2020, 6:52 AM
Zhengrong Yan
Zhengrong Yan - avatar
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)
19th May 2020, 11:10 AM
Raven
Raven - avatar
+ 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>";
19th May 2020, 6:54 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 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.
19th May 2020, 11:12 AM
Raven
Raven - avatar
+ 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.
19th May 2020, 7:01 AM
coddy
coddy - avatar