- hw04 deadline sect.11: Thu 23:59 - quick review of some html concepts - DOM - examples of javascript which modifies the DOM ====== - quick review of some html concepts What's the different between the tags "em" is semantic: emphasis HTML properly shows the *structure* of the document "i" is the details of presentation Presentation SHOULD be handled by css (hence is deprecated) - when using css: There are three ways to associate CSS with a tag: - id #fname { font-style: bold; } - by tag: h3 { font-style: bold; } useful for having a uniform design-feel. (not common, for me) - class: .important { font-style: bold; fg-color: blue; }
  • ...
  • Use meaningful ("semantic") names for your classes. Most html tags convey meaning/structure. There are two tags that don't come with pre-defined meaning: div span These tags, when combined with a meaningul css class-name, kinda become new semantic html tags!! ... I said au revoir to my vacation. --------- DOM -- Document Object Model -- the page's html tree as represented live, in browser's memory. Starts as the html (as a tree); each node (in addition to its children) has its attributes (from html) AND all css attributes (like font-size). It can change as time passes. Note that the html `

    blah

    ` turned into, in the DOM, a h3 node with an attribute "align" whose value is "center". In general, any HTML-attribute becomes a DOM-attribute. With one exception: the HTML-attribute "class" corresponds, in the DOM, to the attribute "classname". [Gotcha!] (reason?: 'class' is a reserved word in javascript?) 'class' vs 'classname' Our favorite javascript function: document.getElementById("fname") -- go to the DOM and grab one node (and return it) Note: `document` is a global variable holding the DOM; this global variable exists only if running javascript inside a browser. // some lines of javascript: var someNode; someNode = document.getElementById("fname"); someNode.align="left"; // we can assign to fields(attributes) of a node // Or just: document.getElementById("fname").align="left"; someNode.style.color = "blue"; someNode.classname = "important"; // change the css class ==== Javascript that modifies the DOM ------------ We want to *generate* tags that look like: Aardvarks
    Bees
    The javascript: document.createElement('a'); (call it `newMenuItem`) think: "" if it were html creates a whole new DOM-node, but it's currently disconnected from the rest of the tree. (We'll attach it later.) newMenuItem.appendChild( document.createTextNode(aChild.id) ) think: "Aardvark" if it were html newMenuItem.setAttribute('href', '#'+aChild.id); think: "Aardvark" if it were html newMenuItem.setAttribute('onclick', ... ) think: "Aardvark" if it were html newMenuItem.setAttribute('onclick', "showJust('" + choiceSourceId + "','" + aChild.id + "');" ); think: "Aardvark" if it were html html / \ head body / | p id='navBar' /|\ a a a