0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【JavaScript】兄弟要素を追加する方法

Posted at

以下のように記述すると兄弟要素を追加できます。

const sample = document.getElementById('sample')
const div = document.createElement('div')

sample.parentNode.insertBefore(div, sample.nextElementSibling)

または以下のように記述します。

const sample = document.getElementById('sample')
const div = document.createElement('div')

sample.parentNode.appendChild(div)

0
0
1

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?