Guest User

Untitled

a guest
Jun 20th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. // First argument (or array element for nested arrays) is tag name.
  2. // Second can optionally be an object, in which case it is used to
  3. // supply attributes. All others are added to the tag's body.
  4. html("p", {"class": "foo"}, "hello world", "!")
  5. '<p class="foo">hello world!</p>'
  6.  
  7. // Shortcuts for denoting id and class attributes
  8. html("p#foo.bar.baz", "hello world!")
  9. '<p id="foo" class="bar baz">hello world!</p>'
  10.  
  11. // Arrays are used for nested tags
  12. html("p", ["span.highlight", "Important!"], " less important")
  13. '<p><span class="highlight">Important!</span> less important</p>'
  14.  
  15. // Simple list example
  16. html("ol", ["li", "first"], ["li", "second"])
  17. '<ol><li>first</li><li>second</li></ol>'
  18.  
  19. // List example with array comprehension - requires JS 1.7
  20. // (but will also combine nicely with Array.map and friends)
  21. html("ul", [["li", item] for each (item in [1, 2, 3])])
  22. '<ul><li>1</li><li>2</li><li>3</li></ul>'
  23.  
  24. // Pass multiple arrays as arguments to get an element list
  25. // instead of a single element
  26. html(["p", "first paragraph"], ["p", "second paragraph"])
  27. '<p>first paragraph</p><p>second paragraph</p>'
Add Comment
Please, Sign In to add comment