DEV Community

Discussion on: Re-implementing jQuery methods in the HTMLElement prototype

Collapse
 
nektro profile image
Meghan (she/her) • Edited

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 })
Collapse
 
jonaskuske profile image
Jonas

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

Collapse
 
jochemstoel profile image
Jochem Stoel

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

Collapse
 
nektro profile image
Meghan (she/her) • Edited

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

Thread Thread
 
daniel15 profile image
Daniel Lo Nigro

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