5
3

More than 5 years have passed since last update.

JavaScript で prependChild

Posted at

昔を思い出しながら、ピュアJSのリハビリ中・・・

Element.prototype.appendChild はあっても、Element.prototype.prependChild はない・・・脳がすっかり jQuery に甘やかされてしまったみたいです。


とりあえずこんな感じで汚染すれば良いかな?

Element.prototype.prependChild = function(el){
    this.insertBefore(el, this.firstChild)
}



こう使う

parentElement.prependChild(childElement);
5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3