開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- JavaScript (プログラミング言語)
- Safari(Web browser)
Eloquent JavaScript(Marijn Haverbeke 著、No Starch Press)のPart 2(Browser)、Chapter 13(The Document Object Model)、Exercises(Elements by Tag Name)を取り組んでみる。
Exercises(Elements by Tag Name)
コード(Emacs)
JavaScript
'use strict'; let div = document.querySelector('#div0'); let getElementsByTagName = (node, tagName) => { let result = [], children = node.children; for (let i = 0, max = children.length; i < max; i += 1) { if (children[i].tagName.toLowerCase() == tagName.toLowerCase()) { result.push(children[i]); } } return result; }; let node = document.getElementsByTagName('body')[0]; div.innerHTML = getElementsByTagName(node, 'div').join('<br>');
0 コメント:
コメントを投稿