InnerHTML attribute

InnerHTML attribute: Used to set or get the content of an HTML element.

Sample code:

<! DOCTYPE HTML < HTML >< head> <meta charset=" utF-8 "> <title></title> </head> <body> <p> <span> let obj = document.getElementById('one'); console.log(obj.innerHTML); obj.innerHTML = '<span>hello world! </span>'; </script> </body> </html>Copy the code

Effect screenshot:

The innerText attribute

InnerText property: Used to set or get plain text in an HTML element.

Sample code:

<! DOCTYPE HTML < HTML >< head> <meta charset=" utF-8 "> <title></title> </head> <body> <p> <span> let obj = document.getElementById('one'); console.log(obj.innerText); obj.innerText = 'hello world! '; </script> </body> </html>Copy the code

Effect screenshot:

The className attribute

ClassName property: Used to set or get the class style of a DOM object.

Sample code:

<! DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <div></div> <script> let obj = document.getElementById('one'); console.log(obj.className); obj.className = 'two'; console.log(obj.className); </script> </body> </html>Copy the code

Effect screenshot:

Style property

Style property: Used to set or get the style of a DOM object.

Sample code:

<! DOCTYPE HTML >< HTML >< head> <meta charset=" UTF-8 "> <title></title> </head> <body> <div> This is a div</div> <script> let obj = document.getElementById('one'); obj.style.width = '500px'; obj.style.height = '300px'; obj.style.backgroundColor = 'gray'; obj.style.fontSize = '20px'; obj.style.color = '#fff'; obj.style.border = 'solid 5px red'; obj.style.display = 'block'; </script> </body> </html>Copy the code

Effect screenshot:



Writing is not easy, read if it helps you, thank you for your support!

If you are a computer terminal, see the lower right corner of the “one button three links”, yes click it [ha ha]




Come on!

Work together!

Keafmd