<1> Css_dom
1,structural Layer
2,presentation Layer
3,behavior Layer
Style is also a property
<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title>Title</title></Head><Body><PID= "text"style= "Background-color: #222222; color:white;">Hello World</P><Scriptsrc= "Cp_10.js"></Script></Body></HTML>
Js:
function sometest () { var text = document.getElementById (' text '); Console.log (typeof text, "text:", text); Console.log (typeof Text.nodename, "NodeName:", text.nodename); Console.log (typeof Text.style, "style:", Text.style);} Sometest ();
Output
Get style properties:
Color= "White"
alert (Text.style.color);
Color: #cc6600;
<2> various ways to set styles:
<p style= "..." > </p>
This is not good and requires external file separation:
If you want to set all of the document's <p> element CSS:
P { background-color: #333333; color: White; }
If you want to set the document ID to text <p> element CSS:
P#text { background-color: #333333; color: White;}
If you want to set the element CSS for document ID text:
#text { background-color: #333333; color: White;}
If you want to set the document class as Textclass element css:
. Textclass { background-color: #333333; color: White;}
However, this is not a way to get the style in the DOM, but it can be set in the DOM.
function () { var text = document.getElementById (' text '); Text.style.backgroundColor= "#222222"; = "White";}
.
Web from getting started to giving up <5>