{"id":4118,"date":"2020-12-30T06:11:23","date_gmt":"2020-12-29T21:11:23","guid":{"rendered":"https:\/\/okamurax.com\/?p=4118"},"modified":"2020-12-30T18:31:11","modified_gmt":"2020-12-30T09:31:11","slug":"javascript-dom%e9%96%a2%e9%80%a3-%e3%83%a1%e3%83%a2","status":"publish","type":"post","link":"https:\/\/appbay.org\/?p=4118","title":{"rendered":"Javascript DOM\u95a2\u9023 \u30e1\u30e2"},"content":{"rendered":"<p>\u30fbDOM\u3001Node\u3001Element<\/p>\n<p>DOM\u306f\u57fa\u672c\u7684\u306a\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u306e\u63d0\u4f9b\u3068\u30c4\u30ea\u30fc\u69cb\u9020\u3092\u4f5c\u3063\u3066\u3044\u308b\u3002<\/p>\n<p>DOM\u3092\u69cb\u6210\u3059\u308b\u5358\u4f4d\u304cNode\u3067\u3001Node\u306f\u6587\u5b57\u5217\u3084\u30b3\u30e1\u30f3\u30c8\u306a\u3069\u3082\u542b\u307e\u308c\u308b\u3002Node\u306e\u4e2d\u3067\u30bf\u30b0\u306e\u90e8\u5206\u304cElement\u3068\u547c\u3070\u308c\u308b\u3002<\/p>\n<p>Element\u306f\u3001\u968e\u5c64\u3067Element\u3001HTMLElement\u3001HTML*Element<br \/>\n\u306e\u3088\u3046\u306b\u7d99\u627f\u3057\u305d\u308c\u305e\u308c\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u6301\u3063\u3066\u3044\u308b\u3002<\/p>\n<p>\u30fb\u578b\u306e\u8abf\u3079\u65b9<\/p>\n<pre class=\"lang:js decode:true\">let el = document.getElementById(\"a\");\r\nalert(Object.prototype.toString.call(el));<\/pre>\n<p>\u30fb\u30bf\u30b0\u3001\u8981\u7d20<\/p>\n<p>\u8981\u7d20\uff1d&lt;\u958b\u59cb\u30bf\u30b0 \u5c5e\u6027&gt;\u5185\u5bb9&lt;\u7d42\u4e86\u30bf\u30b0&gt;<\/p>\n<p>\u30fb\u8981\u7d20\u53d6\u5f97<\/p>\n<p>HTML*Element = document.getElementById(id)<br \/>\nid\u3067\u8981\u7d20\u3092\u53d6\u5f97<\/p>\n<p>HTMLCollection = document.getElementsByTagName(name)<br \/>\n\u30bf\u30b0\u540d\u3067\u8981\u7d20\u3092\u53d6\u5f97<\/p>\n<p>HTMLCollection = document.getElementsByClassName(name)<br \/>\nclass\u3067\u8981\u7d20\u3092\u53d6\u5f97<\/p>\n<p>NodeList = document.getElementsByName(name)<br \/>\nname\u5c5e\u6027\u3067\u8981\u7d20\u3092\u53d6\u5f97<\/p>\n<p>HTML*Element = document.querySelector(selectors)<br \/>\nCSS\u30bb\u30ec\u30af\u30bf\u30fc\u3067\u8981\u7d20(\u6700\u521d\u306e1\u3064)\u3092\u53d6\u5f97<\/p>\n<p>NodeList = document.querySelectorAll(selectors)<br \/>\nCSS\u30bb\u30ec\u30af\u30bf\u30fc\u3067\u8981\u7d20(\u8907\u6570)\u3092\u53d6\u5f97<\/p>\n<p>\u30fbNodeList\u3068HTMLCollection<\/p>\n<p>NodeList\uff1a\u3000\u53d6\u5f97\u5f8c\u66f4\u65b0\u3057\u306a\u3044\u3002<br \/>\nHTMLCollection\uff1a\u3000\u53d6\u5f97\u5f8c\u66f4\u65b0\u3059\u308b\u3002<\/p>\n<p>for &#8230; of \u3067\u56de\u3059<\/p>\n<pre class=\"lang:js decode:true\">let d = document.getElementsByTagName('div');\r\nfor (let e of d) {\r\n  alert(e.textContent);\r\n}<\/pre>\n<p>\u30fb\u8981\u7d20\u53d6\u5f97(\u89aa\u5b50\u95a2\u4fc2)<\/p>\n<p>HTML*Element = el.parentNode<br \/>\n\u89aa\u8981\u7d20<\/p>\n<p>HTML*Element = el.firstElementChild<br \/>\n\u6700\u521d\u306e\u5b50\u8981\u7d20<\/p>\n<p>HTML*Element = el.lastElementChild<br \/>\n\u6700\u5f8c\u306e\u5b50\u8981\u7d20<\/p>\n<p>HTMLCollection = el.children<br \/>\n\u5b50\u8981\u7d20\u30ea\u30b9\u30c8<\/p>\n<p>HTML*Element = el.previousElementSibling<br \/>\n1\u3064\u524d\u306e\u8981\u7d20<\/p>\n<p>HTML*Element = el.nextElementSibling<br \/>\n1\u3064\u5f8c\u306e\u8981\u7d20<\/p>\n<p>\u30fb\u8981\u7d20\u64cd\u4f5c<\/p>\n<p>HTML*Element = document.createElement(\u30bf\u30b0)<br \/>\n\u6307\u5b9a\u30bf\u30b0\u3067\u8981\u7d20\u3092\u4f5c\u6210<\/p>\n<p>parentNode.insertBefore(newNode, referenceNode)<br \/>\nreferenceNode\u306e\u524d\u306bnewNode\u3092\u8ffd\u52a0<\/p>\n<p>parentNode.appendChild(newNode)<br \/>\n\u6700\u5f8c\u306bnewNode\u3092\u8ffd\u52a0<\/p>\n<p>parentNode.removeChild(childNode)<br \/>\nchildNode\u3092\u524a\u9664<\/p>\n<p>\u30fb\u5185\u5bb9\u64cd\u4f5c<\/p>\n<p>string = el.innerHTML<br \/>\n\u30bf\u30b0\u304c\u89e3\u6790\u3055\u308c\u308b\u3002<\/p>\n<p>string = el.textContent \/ el.innerText<br \/>\n\u30bf\u30b0\u304c\u89e3\u6790\u3055\u308c\u306a\u3044\u3002\u53d6\u5f97\u3059\u308b\u3068\u30bf\u30b0\u306f\u306a\u304f\u306a\u308a\u3001\u8a2d\u5b9a\u3059\u308b\u3068\u30bf\u30b0\u306f\u6587\u5b57\u5217\u306b\u306a\u308b\u3002<\/p>\n<p>textContent\u3068\u3001innerText\u306e\u9055\u3044\u3002<br \/>\ntextContent\u306f\u6539\u884c\u30b3\u30fc\u30c9\u306a\u3069\u306f\u7dad\u6301\u3055\u308c\u3001innerText\u5909\u63db\u3055\u308c\u308b\u306a\u3069\u3044\u304f\u3064\u304b\u3042\u308b\u3002<\/p>\n<p>\u30fb\u5c5e\u6027\u64cd\u4f5c<\/p>\n<p>string = el.getAttribute(name)<br \/>\n\u5c5e\u6027\u3092\u53d6\u5f97<\/p>\n<p>el.setAttribute(name, value)<br \/>\n\u5c5e\u6027\u3092\u8a2d\u5b9a<\/p>\n<p>el.removeAttribute(name)<br \/>\n\u5c5e\u6027\u3092\u524a\u9664<\/p>\n<p>bool = el.hasAttribute(name)<br \/>\n\u5c5e\u6027\u3092\u6301\u3063\u3066\u3044\u308b\u304b\u3069\u3046\u304b<\/p>\n<p>\u30fbclassList<\/p>\n<p>string = el.className<br \/>\nclass\u306e\u78ba\u8a8d<\/p>\n<p>el.classList.add(name)<br \/>\nclass\u306e\u8ffd\u52a0<\/p>\n<p>el.classList.remove(name)<br \/>\nclass\u306e\u524a\u9664<\/p>\n<p>el.classList.toggle(name)<br \/>\nclass\u306eOn\/Off<\/p>\n<p>bool = el.classList.contains(name)<br \/>\nclass\u6709\u7121<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30fbDOM\u3001Node\u3001Element DOM\u306f\u57fa\u672c\u7684\u306a\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u306e\u63d0\u4f9b\u3068\u30c4\u30ea\u30fc\u69cb\u9020\u3092\u4f5c\u3063\u3066\u3044\u308b\u3002 DOM\u3092\u69cb\u6210\u3059\u308b\u5358\u4f4d\u304cNode\u3067\u3001Node\u306f\u6587\u5b57\u5217\u3084\u30b3\u30e1\u30f3\u30c8\u306a\u3069\u3082\u542b\u307e\u308c\u308b\u3002Node\u306e\u4e2d\u3067\u30bf\u30b0\u306e\u90e8\u5206\u304cElement\u3068 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/appbay.org\/?p=4118\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Javascript DOM\u95a2\u9023 \u30e1\u30e2&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[4],"class_list":["post-4118","post","type-post","status-publish","format-standard","hentry","category-1","tag-javascript-typescript"],"_links":{"self":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/4118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4118"}],"version-history":[{"count":5,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/4118\/revisions"}],"predecessor-version":[{"id":4125,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/4118\/revisions\/4125"}],"wp:attachment":[{"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}