Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Working with the DOM and Living to Tell

Working with the DOM and Living to Tell

Ever wondered why it's hard to have all browsers act the same? This is a brief talk about the DOM. What it is, where it came from and why it's giving us headaches. The challenges of working with it are extracted from the writing of a text-styling jQuery plugin – cramify.js.

Cassian LUP

June 17, 2015
Tweet

More Decks by Cassian LUP

Other Decks in Technology

Transcript

  1. DOM Level 0 / HTML 4 1995 Intermediate DOM /

    DHTML,
 ECMAScript 1997 1998 DOM Level 1 / weak browser upgrades 2000 DOM Level 2 / getElementById 1994 W3C 2004 DOM Level 3 / keyboard DOM Level 4 / Draft 2014
  2. The Document Object Model (DOM) is a platform- and language-neutral

    interface that will allow programs and scripts to dynamically access and update the content, structure and style of documents. (w3.org/DOM)
  3. • Interact with it (JS, CSS) • Nodes (elements) •

    Parents & Children (inheritance) wikipedia.org
  4. • Interact with it (JS, CSS) • Nodes (elements) •

    Parents & Children (inheritance) • Events wikipedia.org
  5. • Interact with it (JS, CSS) • Nodes (elements) •

    Parents & Children (inheritance) • Events • ≠ HTML (a markup
 language that enables
 representing a certain 
 kind of DOM in text.) wikipedia.org
  6. • Designed for C, C++, JAVA, JavaScript and others. •

    "A camel is a horse designed by committee.” (source)
  7. • Designed for C, C++, JAVA, JavaScript and others. •

    "A camel is a horse designed by committee.” (source) • Implemented in each browser, differently. (!!)
  8. • Designed for C, C++, JAVA, JavaScript and others. •

    "A camel is a horse designed by committee.” (source) • Implemented in each browser, differently. (!!) quirksmode.org
  9. Headaches! (link) • Getting the Cursor Position • Getting the

    Size of the Viewport, or Browser Window • IE, background transparent click (and many many many others) • DOM Ready (38-line solution) Solutions? • jQuery, • MooTools, • Prototype, • CSS Resets.
  10. 1. Default Behaviour the quick brown fox jumps over the

    lazy dog <div> the quick brown fox jumps over the lazy dog </div>
  11. 2. Add CSS the quick brown fox jumps over the

    lazy dog <div class=“styled”> the quick brown fox jumps over the lazy dog </div>
  12. 3. Uppercase & Line Breaks THE QUICK BROWN FOX JUMPS

    OVER THE LAZY DOG <div class=“styled”> THE QUICK<br> BROWN<br> FOX<br> JUMPS OVER THE<br> LAZY DOG<br> </div>
  13. 4. Separate Lines THE QUICK BROWN FOX JUMPS OVER THE

    LAZY DOG <div class=“styled”> <div class=“line”>THE QUICK</div> <div class=“line”>BROWN</div> <div class=“line”>FOX</div> <div class=“line”>JUMPS OVER THE</div> <div class=“line”>LAZY DOG</div> </div>
  14. 6. Do the Math (Rule of Three, anybody?) THE QUICK

    BROWN FOX JUMPS OVER THE LAZY DOG
  15. 6. Do the Math (Rule of Three, anybody?) THE QUICK

    BROWN FOX JUMPS OVER THE LAZY DOG
  16. Advantages • OS-agnostic • Infinite font support • Dynamic rendering

    Disvantages • Performance issues - use cookies!