re: Re-implementing jQuery methods in the HTMLElement prototype VIEW POST

FULL DISCUSSION
 

Some notes:

  • $$('p', $('article')) returns all <p> elements in the first <article>, not all <p>s that are children of <article>s. For that you'd still have to do $$("article > p")
  • HTMLElement.prototype.has = HTMLElement.prototype.hasAttribute doesn't bind the function properly, so this will not work properly
  • your .text() function should use .textContent not .innerText
  • HTMLElement.append should still check to see if child is an instance of Node, even if it's not an HTMLElement
  • Same with HTMLElement.prototype.prepend
  • Also HTMLElement.prototype.prepend, already exists
  • HTMLElement.prototype.remove already exists too
  • HTMLElement.prototype.parent should return .parentElement
  • HTMLElement.prototype.emit should have args=null as a parameter and use new CustomEvent(event, { detail:args })
 

HTMLElement.prototype.append and NodeList.prototype.forEach already exist, too.

 

Thanks I fixed the things you said in updated gist. Why does text need to return textContent and not innerText?

 

innerText is a lot more performance heavy and triggers layout to be recalculated.
stackoverflow.com/a/35213639/5203655

AFAIK, innerText is also non-standard (originally IE-only) whereas textContent is part of the standard.

code of conduct - report abuse