selectors { style-property : value; ... } example: body { padding:5%; background-color: #ddd; }
htmltags: body, div, span, img, ... custom-tags: nav-keys, spacer-10, ... .classnames: .indent, .undent, .photo, ... #idnames: #placeHolder, #mastheadPhoto, ... psuedo-classes: a:link, a:hover, ... psuedo-elements: p::first-letter, p::first-line, ... attributes: [attr], [attr=value], ...
s1, s2, ... applied to s1 and s2 and ... s1 s2 applied to s2 if it has s1 ancestor s1 > s2 applied to s2 if it has s1 parent s1 + s2 applied to s2 if it has adjacent sibling s1 s1 ~ s2 applied to s2 if it has sibling s1
ol, ul { margin-top:10px; margin-bottom: 10px; } // all ordered and unordered lists div li { background-color: #dddddd; } // all list items with div ancestor div.indent > p { color: #333333; } // all paragraphs that are children // of div with class indent
Method | Description |
---|---|
document.getElementById("anid"") |
Returns node object of element with id="anid" if found, else null.
Note: ids should be unique. If not unique, returns first found. |
document.getElementByTagName("div") | Returns list of node objects that are divs, if any found, else null. |
document.getElementByClassName("darkItem") | Returns list of node objects with class darkItem, if any found, else null. |
document.querySelectorAll("div.tight") | Returns list of node objects that are div's with class tight if any, else null. |
document.createElement("div") | Returns a new div node |
node.removeChild(childElement) | removes specified child, returns removed element |
node.appendChild(element) | appends existing element to node |
DOM Properties | Description |
HTML elements -> nodes HTML attributes -> properties |
HTML markup contains elements that may have attributes like src="url". When the HTML code is parsed it becomes a DOM tree with nodes that have properties for each of the source's element attribures. |
node.innerHTML | get or set the body of an Element by reading or supplying markup |
node.attribute |
get or set: href, src, width, height, style, title, ...
lower-case attribute names with quoted values is preferred |