Skip to content

Instantly share code, notes, and snippets.

@FelixAkk
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save FelixAkk/708a871755fbd4342b70 to your computer and use it in GitHub Desktop.

Select an option

Save FelixAkk/708a871755fbd4342b70 to your computer and use it in GitHub Desktop.
The cure for the disease of div-itis
# Heads up to front-end developers!
# $.append isn’t the only DOM insertion function!
# It requires containers to append elements into.
# It’s the primary source of excessive div-itis.
# Abandon the practice of e.g.
# @$(‘div.itself div.container div.sub-container div.collection div.comments’).append($comments)
# And switch to the more semantic:
@place = @$("header").after
@place($body)
# Wrap with $.proxy when sending out of context, e.g.
super
place: $.proxy(@$header.after, @$header)
# So that views like collections can
place(child.$el) for child in @childs
# In flat DOM structures, when they should be kept flat
# So next time you create a composite view ;)
@$("div.message").after(@comments.$el)
# Which sadly reads the other way around; after message comes comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment