jquery mini

by jeevankk

HTML

<body>
  <div class="name">hello
  </div>
  <div class="name">hello - 1
  </div>
  <div class="name">hello - 2
  </div>
  <div class="different-name"> hello - 3 - 
  </div>
</body>

JavaScript

function jQuery(selector, context) {
  if (!selector)
    return this;
  this.elements = document.querySelectorAll(selector);
  return this;
}

jQuery.prototype.html = function(content) {
  for (let i = 0; i < this.elements.length; i++)
    this.elements[i].innerHTML = content + ' ' + i;
  return this;
}

function $(selector) {
  return new jQuery(selector);
}

$('.name').html('Good bye ');