Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
CoffeeScript version of jQuery DOM Shortcut
do ->
setOptions = (el, attributes) ->
for own key, value of attributes
el.setAttribute key, value
_(['ol','ul','li','span','strong','p','h1','h2','h3','h4']).each (tag) ->
window["_#{tag}"] = (html, attributes, children...) ->
el = document.createElement tag
if attributes?
if attributes.jquery?
children.unshift attributes
el = setOptions el, attributes
if html?
if html.jquery?
children.unshift attributes
if typeof html is 'object'
el = setOptions el, html
else if typeof html is 'string'
el.innerHTML = html
el = $(el)
for child in children
el.append child
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment