Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // First argument (or array element for nested arrays) is tag name.
- // Second can optionally be an object, in which case it is used to
- // supply attributes. All others are added to the tag's body.
- html("p", {"class": "foo"}, "hello world", "!")
- '<p class="foo">hello world!</p>'
- // Shortcuts for denoting id and class attributes
- html("p#foo.bar.baz", "hello world!")
- '<p id="foo" class="bar baz">hello world!</p>'
- // Arrays are used for nested tags
- html("p", ["span.highlight", "Important!"], " less important")
- '<p><span class="highlight">Important!</span> less important</p>'
- // Simple list example
- html("ol", ["li", "first"], ["li", "second"])
- '<ol><li>first</li><li>second</li></ol>'
- // List example with array comprehension - requires JS 1.7
- // (but will also combine nicely with Array.map and friends)
- html("ul", [["li", item] for each (item in [1, 2, 3])])
- '<ul><li>1</li><li>2</li><li>3</li></ul>'
- // Pass multiple arrays as arguments to get an element list
- // instead of a single element
- html(["p", "first paragraph"], ["p", "second paragraph"])
- '<p>first paragraph</p><p>second paragraph</p>'
Add Comment
Please, Sign In to add comment