1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

javascriptの要素アクセス諸々

Posted at

HTML要素のタグ内のドキュメント取得

innerHTML:HTMLタグを含めた文字列
textContent:HTMLタグを除いた文字列

HTML要素のタグ内のドキュメント設定

textContent:HTMLタグがない場合
HTMLタグ含めたい場合はcreateElementやcreateTextNodeでタグ要素を生成して
appendChildで挿入する

HTML要素の親子取得

<ul id="login-users">
<li id="suzuki-dhyi">suzuki</li>
<li id="tanaka-ddha">tanaka</li>
<li id="sato-xydu">sato</li>
</ul>
// ul要素取得
let ul = document.getElementById('login-users');
// 添え字アクセス
let _user = ul.children;
_user[0];
_user[1];
 
// 子要素をループで回す
Array.from(ul.children).forEach(user => {
console.log(user);
});
// 子要素から親要素を取得
let user1 = document.getElementById('suzuki-dhyi');
let par = user1.parentNode;

// 要素内の検索
let tanaka = ul.querySelector('tanaka-ddha');

// 子要素の末尾に追加:appendChild
// 子要素の最初に追加:insertBefore

// 要素の削除:remove
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?