Getting the wrong element in click handler with overlapping "circle" divs
<p>I am trying dynamically add HTML elements with click handlers. When the click handler is activated it targets wrong element(it always target the outer circle). Where could be the problem? </p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>(function() {

  //selector, jQuery style
  var $ = function(selector) {
    return document.querySelector(selector);
  }

  //getting quantity of circles
  var quantity = $('.circles').getAttribute('quantity');

  //setting outer width/height for circles
  $('.circles').style.width = (quantity * 50) + 4 + 'px';
  $('.circles').style.height = (quantity * 50) + 4 + 'px';

  //creating element for children
  var childCircle = document.createElement('div');
  childCircle.className = 'subCircle';

  //click function for children
  function onClick() {
    this.attributes.style.value += 'border-color: red;'
    alert(this.clientHeight);
  }

  //append sub circles
  for (var i = 0; i &lt; quantity; i++) {
    $('.circles').appendChild(childCircle.cloneNode());
  }

  //iterate over .circles .subCircle and add onClick function for each subCircle and css aswell

  var subCircle = $('.circles').getElementsByClassName('subCircle');
  for (var i = 0; i &lt; subCircle.length; i++) {
    subCircle[i].onclick = onClick;
    subCircle[i].style.width = ((i + 1) * 50) + 'px';
    subCircle[i].style.height = ((i + 1) * 50) + 'px';
  }

})();</code></pre>
<pre class="snippet-code-css lang-css prettyprint-override"><code>.circles {
  position: absolute;
}

.subCircle {
  position: absolute;
  border-radius: 50%;
  transform: translateX(-50%) translateY(-50%);
  border: 2px solid black;
  top: 50%;
  left: 50%;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;body&gt;
  &lt;div class="circles" quantity=10&gt;&lt;/div&gt;
&lt;/body&gt;</code></pre>
</div>
</div>
</p>

<p>Also on jsFiddle: <a href="https://jsfiddle.net/martin_borman/1srkL5bf/" rel="nofollow">https://jsfiddle.net/martin_borman/1srkL5bf/</a></p>