title: add class to div according to where the cursor is
body: <p>I am trying to add a class to a div when a button is clicked according to which div last had focus.</p>
  
  <p>i can get the id of the div but not on button click</p>
  
  <pre><code>&lt;div contenteditable="true" id="duck"&gt;one&lt;/div&gt;
  &lt;div contenteditable="true" id="dog"&gt;two&lt;/div&gt;
  &lt;div contenteditable="true" id="cat"&gt;three&lt;/div&gt;
  &lt;input type="label" id="showValue"&gt;&lt;/input&gt;
  
  &lt;button id="clickMe"&gt;Click me&lt;/button&gt;
  </code></pre>
  
  <p>and the js</p>
  
  <pre><code>var divbox = document.getElementsByTagName('div');
  
  for (var i = 0; i &lt; divbox.length; i++)
    divbox[i].addEventListener('focus', function() {
      $('#showValue')[0].value = this.id;    
    }, false);
  
  
  $('#clickMe').click(function() {
   alert(divbox)
  });
  </code></pre>
  
  <p>fiddle <a href="http://jsfiddle.net/ktcle/sf9vrj9L/" rel="nofollow noreferrer">http://jsfiddle.net/ktcle/sf9vrj9L/</a></p>