       $('.close-graph').click (event) ->
         event.preventDefault()
         $(this).parent().remove()
-        $("#menu-container a[data-div-id=#{$(this).attr('data-div-id')}]").removeClass('selected')
+        dataDivId = $(this).attr('data-div-id')
+        $("#menu-container a[data-div-id=#{dataDivId}]").removeClass('selected')
 
       $(this).toggleClass('selected')
 

      for u in v.urls
        divid = u.url.replace(/\./g, '_') # '.' in id breaks jQuery!
        $("#menu-container>ul>li[id=#{k}]>ul")
          .append("<li><a title='show/hide graph for #{u.year} #{u.month}' href='javascript:void(0)' data-div-id=#{divid} data-url=#{u.url}>#{u.year} #{u.month}</a></li>")
    $('#menu-container a').click ->
      # TODO move remaining code into Graph method
      anchor = this

          <div class=dygraph id=#{divid}><span class=loading>loading</span></div>
          </div")
        g = new Graph
          name: $(this).attr('data-title')
          url: $(this).attr('data-url')
          div: divid
        .create()
