å
容
ãã©ãŠã¶ã§WebããŒãžãéããšãHTMLãœãŒã¹ã³ãŒããåãåããïŒãããïŒ11ç« ã®ããŒãµãŒãããã°ã©ã ãè§£æããããã«è§£æããŸãã ãã©ãŠã¶ã¯ããã¥ã¡ã³ãæ§é ã®ã¢ãã«ãæ§ç¯ããããã䜿çšããŠç»é¢ã«ããŒãžãæç»ããŸãã
ãã®ããã¥ã¡ã³ãã®è¡šçŸã¯ãJavaScriptãµã³ãããã¯ã¹ã§å©çšã§ããããã¡ãã®1ã€ã§ãã èªãã§å€æŽããããšãã§ããŸãã ãªã¢ã«ã¿ã€ã ã§å€æŽãããŸããä¿®æ£ãããšããã«ãç»é¢äžã®ããŒãžãæŽæ°ããã倿Žãåæ ãããŸãã
ææžæ§é
HTMLã¯ãã¹ããããããã¯ã¹ã®ã³ã¬ã¯ã·ã§ã³ãšèããããšãã§ããŸãã ã¿ã°ã«ã¯ä»ã®ã¿ã°ãå«ãŸããŠããããã§ãã¿ã°ã«ã¯ããã¹ããŸãã¯ã¿ã°ãå«ãŸããŠããŸãã åç« ã®ãµã³ãã«ææžã次ã«ç€ºããŸãã
<!doctype html> <html> <head> <title> </title> </head> <body> <h1> </h1> <p>, .</p> <p> ! <a href="http://eloquentjavascript.net"></a>.</p> </body> </html>
ãã®ããŒãžã®æ§é ã¯æ¬¡ã®ãšããã§ãã

ãã©ãŠã¶ãããã¥ã¡ã³ãã衚ãããã«äœ¿çšããããŒã¿æ§é ã¯ããã®åœ¢ç¶ãåæ ããŠããŸãã åããã¯ã¹ã«ã¯ãçžäºäœçšããããã«é¢ããããŸããŸãªããŒã¿ãèŠã€ããããšãã§ãããªããžã§ã¯ãããããŸã-ã©ã®ã¿ã°ã衚ãããã©ã®ããã¯ã¹ãšããã¹ããå«ãŸãããã ãã®ãã¥ãŒã¯ãããã¥ã¡ã³ããªããžã§ã¯ãã¢ãã«ããŸãã¯ç¥ããŠDOMãšåŒã°ããŸãã
ã°ããŒãã«å€æ°ããã¥ã¡ã³ããä»ããŠãããã®ãªããžã§ã¯ãã«ã¢ã¯ã»ã¹ã§ããŸãã ãã®documentElementããããã£ã¯ãã¿ã°ã衚ããªããžã§ã¯ããåç
§ããŸãã ãŸãã察å¿ããèŠçŽ ã®ãªããžã§ã¯ããå«ãheadããããã£ãšbodyããããã£ãæäŸããŸãã
æšã
第11ç« ã®æ§æããªãŒãæãåºããŠãã ããããããã®æ§é ã¯ããã©ãŠã¶ããã¥ã¡ã³ãã®æ§é ã«éåžžã«äŒŒãŠããŸãã åããŒãã¯ä»ã®ããŒããåç
§ã§ããåãã©ã³ãã¯ç¬èªã®ãã©ã³ããæã€ããšãã§ããŸãã ãã®æ§é ã¯ããã¹ããããæ§é ã®å
žåçãªäŸã§ãããèŠçŽ ã«ã¯ããèªäœã«é¡äŒŒãããµãèŠçŽ ãå«ãŸããŸãã
ããŒã¿æ§é ã¯ãåå²ãããµã€ã¯ã«ããªãïŒããŒãèªäœãå«ãããšã¯ã§ããŸããïŒãåäžã®çºé³ããããã«ãŒãããæã€å ŽåãããªãŒãšåŒã°ããŸãã DOMã®å Žåãdocument.documentElementã¯ã«ãŒããšããŠæ©èœããŸãã
ããªãŒã¯èšç®ç§åŠã§ããèŠãããŸãã HTMLããã¥ã¡ã³ããããã°ã©ã ã®ãããªååž°æ§é ã衚ãããšã«å ããŠãéåžžãèŠçŽ ã¯ãœãŒãããã1次å
é
åããããœãŒããããããªãŒãèŠã€ãããæ¿å
¥ãããããã®ã§ããœãŒããããããŒã¿ã»ãããæäœããããã«äœ¿çšãããŸãã
å
žåçãªããªãŒã«ã¯ç°ãªãããŒãããããŸãã Eggã®æ§æããªãŒã«ã¯ã倿°ãå€ãããã³ã¢ããªã±ãŒã·ã§ã³ããããŸããã ã¢ããªã±ãŒã·ã§ã³ã«ã¯åžžã«åãã©ã³ããããã倿°ãšå€ã¯ãèããã€ãŸãåãã©ã³ãã®ãªãããŒãã§ããã
DOMã«ã€ããŠãåãããšãèšããŸãã HTMLã¿ã°ã衚ãéåžžã®èŠçŽ ã®ããŒãã¯ãããã¥ã¡ã³ãã®æ§é ãå®çŸ©ããŸãã åããŒããæã€å ŽåããããŸãã ãã®ãããªããŒãã®äŸã¯document.bodyã§ãã ãããã®åããŒãã®äžéšã¯èã®ããã«èŠããå ŽåããããŸã-ããšãã°ãããã¹ããŸãã¯ã³ã¡ã³ãïŒHTMLã§ã¯ãã³ã¡ã³ãã¯æåã®éã«æžã蟌ãŸããŸãïŒã
åDOMããŒããªããžã§ã¯ãã«ã¯nodeTypeããããã£ããããããŒãã®ã¿ã€ããæ±ºå®ããããžã¿ã«ã³ãŒããå«ãŸããŠããŸãã éåžžã®èŠçŽ ã®å Žåã¯1ã§ãããããã¯document.ELEMENT_NODE宿°ããããã£ãšããŠãå®çŸ©ãããŠããŸãã ããã¹ãã®ãã©ã°ã¡ã³ãã衚ãããã¹ãããŒãã®å Žåã3ïŒdocument.TEXT_NODEïŒã§ãã ã³ã¡ã³ãã«ã¯8ïŒdocument.COMMENT_NODEïŒããããŸãã
ã€ãŸããããã¥ã¡ã³ãããªãŒãã°ã©ãã£ã«ã«ã«è¡šãå¥ã®æ¹æ³ã次ã«ç€ºããŸãã

èã¯ããã¹ãããŒãã§ãããç¢å°ã¯ããŒãéã®èŠªåé¢ä¿ã瀺ããŸãã
æšæº
ããŒãã¿ã€ãã衚ãããã«æå·æ°åã䜿çšããããšã¯ãJavaScriptã¹ã¿ã€ã«ã®ã¢ãããŒãã§ã¯ãããŸããã åŸã»ã©ãDOMã€ã³ã¿ãŒãã§ãŒã¹ã®ä»ã®éšåã«äŒããŸããããããç°è³ªã§æ±ãã«ããããã§ãã ãã®çç±ã¯ãDOMã¯JavaScriptå°çšã§ã¯ãªãã£ãããã§ãã 圌ã¯ä»ã®ã·ã¹ãã ã§äœ¿çšã§ããèšèªã«äŸåããªãã€ã³ã¿ãŒãã§ãŒã¹ãå®çŸ©ããããšããŠããŸã-HTMLã ãã§ãªããHTMLã«äŒŒãæ§æãæã€æ±çšããŒã¿åœ¢åŒã§ããXMLã§ãã
ããã¯äžå¿«ã§ããããšã倿ããŸããã æšæºã¯éåžžã«æçšãªãã®ã§ãããç§ãã¡ã®å Žåãèšèªããã®ç¬ç«æ§ã®å©ç¹ã¯ããã»ã©æçšã§ã¯ãããŸããã ããŸããŸãªèšèªã䜿çšããå Žåã«éŠŽæã¿ã®ããã€ã³ã¿ãŒãã§ã€ã¹ãããã䜿çšããŠããèšèªã«ããé©åããã€ã³ã¿ãŒãã§ã€ã¹ã䜿çšããããšããå§ãããŸãã
èšèªãšã®äžäŸ¿ãªçµ±åã瀺ãããã«ãDOMããŒããæã€childNodesããããã£ãæ€èšããŠãã ããã lengthããããã£ãæã€é
åã®ããã«èŠãããªããžã§ã¯ããšãåããŒãã«ã¢ã¯ã»ã¹ããããã®çªå·ä»ãããããã£ãå«ãŸããŠããŸãã ãã ããããã¯NodeListåã®ã€ã³ã¹ã¿ã³ã¹ã§ãããå®éã®é
åã§ã¯ãªããããforEachã®ãããªã¡ãœããã¯ãããŸããã
貧匱ãªã·ã¹ãã èšèšã«é¢é£ããåé¡ããããŸãã ããšãã°ãæ°ããããŒããäœæããŠãããã«ããããã£ãŸãã¯åããŒãã远å ããããšã¯ã§ããŸããã æåã«äœæããæ¬¡ã«åã1ã€ãã€è¿œå ããæåŸã«å¯äœçšã䜿çšããŠããããã£ã1ã€ãã€å²ãåœãŠãŸãã DOMãšç·å¯ã«é£æºããã³ãŒãã¯é·ããèŠèŠãããç¹°ãè¿ããå€ããªããŸãã
ãããããããã®åé¡ã¯èŽåœçã§ã¯ãããŸããã JavaScriptã䜿çšãããšãæœè±¡åãäœæã§ããŸãã æäœãããæç¢ºãã€ç°¡æœã«è¡šçŸã§ããè£å©é¢æ°ãç°¡åã«äœæã§ããŸãã äžè¬ã«ããããã®ã¿ã€ãã®ããŒã«ã¯ããã©ãŠã¶ã®ããã°ã©ãã³ã°ãç®çãšããå€ãã®ã©ã€ãã©ãªãæäŸããŸãã
æšã®æ£æ©
DOMããŒãã«ã¯ãè¿é£ããŒããžã®å€ãã®ãªã³ã¯ãå«ãŸããŠããŸãã ãããå³ã«ç€ºããŸãã

ããã«ã¯åã¿ã€ãã®ãªã³ã¯ã1ã€ã ã衚瀺ãããŠããŸãããåããŒãã«ã¯èŠªããŒããæãparentNodeããããã£ããããŸãã ãŸããåèŠçŽ ããŒãïŒã¿ã€ã1ïŒã«ã¯ãåããŒããå«ãé
åã®ãããªãªããžã§ã¯ããæãchildNodesããããã£ããããŸãã
çè«çã«ã¯ããããã®ãªã³ã¯ã®ã¿ã䜿çšããŠããªãŒã®ä»»æã®éšåã«ç§»åã§ããŸãã ããããJavaScriptã¯å€ãã®è¿œå ã®ãã«ããªã³ã¯ãæäŸããŸãã firstChildããã³lastChildããããã£ã¯ãæåãšæåŸã®åãæãããåãæããªãããŒãã®å Žåã¯nullãå«ã¿ãŸãã previousSiblingããã³nextSiblingã¯ã飿¥ããŒããæããŸã-çŸåšã®ããŒããšåã芪ã®ããŒãã§ãããçŸåšã®ããŒãã®çŽåãŸãã¯çŽåŸã®ãªã¹ãã«ãããŸãã æåã®ããŒãã®previousSiblingããããã£ã¯nullã§ãlastSiblingã¯æåŸã®nullã§ãã
ãã®ãããªãã¹ããããæ§é ã䜿çšããå Žåãååž°é¢æ°ã圹ç«ã¡ãŸãã æ¬¡ã¯ãæå®ãããæååãå«ãããã¹ãããŒããããã¥ã¡ã³ãã§æ€çŽ¢ããèŠã€ãã£ãå Žåã«trueãè¿ããŸãã
function talksAbout(node, string) { if (node.nodeType == document.ELEMENT_NODE) { for (var i = 0; i < node.childNodes.length; i++) { if (talksAbout(node.childNodes[i], string)) return true; } return false; } else if (node.nodeType == document.TEXT_NODE) { return node.nodeValue.indexOf(string) > -1; } } console.log(talksAbout(document.body, ""));
ããã¹ãããŒãããããã£nodeValueã«ã¯ãããã¹ãã®è¡ãå«ãŸããŠããŸãã
ã¢ã€ãã ãæ€çŽ¢ãã
芪ãåãå
åŒã®éã§ãããã®ãªã³ã¯ãããã²ãŒãããããã¥ã¡ã³ãå
šäœãé²èЧãããšäŸ¿å©ãªå ŽåããããŸãã ãã ããããã¥ã¡ã³ãã«ç¹å®ã®ããŒããå¿
èŠãªå Žåã¯ãdocument.bodyããå§ããŠãã³ãŒãå
ã®ããŒãã³ãŒãã£ã³ã°ããããã¹ãæãã«äžŠã¹æ¿ããã®ã¯éåžžã«äžäŸ¿ã§ãã ãã®éãããã°ã©ã å
ã®ããã¥ã¡ã³ãã®æ£ç¢ºãªæ§é ã«ã€ããŠæ³å®ããŸããåŸã§å€æŽããããšãã§ããŸãã å¥ã®è€éãªèŠå ã¯ãããŒãéã®ã¹ããŒã¹ã«å¯ŸããŠãããã¹ãããŒããäœæãããããšã§ãã ãã®äŸã®ããã¥ã¡ã³ãã§ã¯ãbodyã¿ã°ã«ã¯3ã€ã®åïŒh1ãš2ã€ã®pïŒããããŸãããã7ã€ã®åããããŸãã
ãããã£ãŠããªã³ã¯ããhref屿§ãå¿
èŠãªå Žåãããã°ã©ã ã«ãdocument.bodyã®6çªç®ã®åã®2çªç®ã®åãã®ãããªèšè¿°ãããªãã§ãã ããã ãããã¥ã¡ã³ãå
ã®æåã®ãªã³ã¯ããšèšãããšãã§ããã°ããè¯ãã§ãããã ãããŠããªããã§ããããšïŒ
var link = document.body.getElementsByTagName("a")[0]; console.log(link.href);
ãã¹ãŠã®èŠçŽ ããŒãã«ã¯getElementsByTagNameã¡ãœãããããããã®ããŒãããïŒçŽæ¥ãŸãã¯éçŽæ¥ã®åå«ïŒç¹å®ã®ã¿ã°ãæã€ãã¹ãŠã®èŠçŽ ãåéããé
åã®ãããªãªããžã§ã¯ããšããŠè¿ããŸãã
ç¹å®ã®ããŒããèŠã€ããã«ã¯ããã®ããŒãã«id屿§ãèšå®ããdocument.getElementByIdã¡ãœããã䜿çšã§ããŸãã
<p> :</p> <p><img id="gertrude" src="img/ostrich.png"></p> <script> var ostrich = document.getElementById("gertrude"); console.log(ostrich.src); </script>
3çªç®ã®ã¡ãœããã¯getElementsByClassNameã§ããããã¯ãgetElementsByTagNameãšåæ§ã«ãèŠçŽ ããŒãã®ã³ã³ãã³ããæ€çŽ¢ããæå®ãããæååãã¯ã©ã¹ã«å«ããã¹ãŠã®èŠçŽ ãè¿ããŸãã
ããã¥ã¡ã³ãã倿Žãã
DOMæ§é ã®ã»ãšãã©ãã¹ãŠã倿Žã§ããŸãã èŠçŽ ããŒãã«ã¯ããããã倿Žããããã«äœ¿çšãããäžé£ã®ã¡ãœããããããŸãã removeChildã¡ãœããã¯ãæå®ãããåããŒããåé€ããŸãã ããŒãã远å ããã«ã¯ãappendChildã䜿çšããŠããŒãããªã¹ãã®æåŸã«è¿œå ããããinsertBeforeã䜿çšããŠãæåã®åŒæ°ã§æž¡ãããããŒãã2çªç®ã®åŒæ°ã§æž¡ãããåã«è¿œå ããŸãã
<p></p> <p></p> <p></p> <script> var paragraphs = document.body.getElementsByTagName("p"); document.body.insertBefore(paragraphs[2], paragraphs[0]); </script>
ããŒãã¯ãããã¥ã¡ã³ãå
ã®1ã€ã®å Žæã«ããååšã§ããŸããã ãããã£ãŠã段èœãOneãã®åã«æ®µèœãThreeããæ¿å
¥ãããšãå®éã«ãªã¹ãã®æ«å°Ÿããåé€ããŠå
é ã«æ¿å
¥ãããThree / One / TwoããååŸããŸãã ããŒããæ¿å
¥ãããã¹ãŠã®æäœã¯ãçŸåšã®äœçœ®ïŒååšããå ŽåïŒããæ¶ããŸãã
replaceChildã¡ãœããã¯ãããåããŒããå¥ã®åããŒãã«çœ®ãæããããã«äœ¿çšãããŸãã æ°ããããŒããšäº€æãå¿
èŠãªããŒãã®2ã€ã®ããŒããåãå
¥ããŸãã 眮ãæããããããŒãã¯ãã¡ãœãããåŒã³åºããŠããèŠçŽ ã®åã§ããå¿
èŠããããŸãã replaceChildãšinsertBeforeã¯ã©ã¡ãããæåã®åŒæ°ãšããŠæ°ããããŒããåãåãããšãæ³å®ããŠããŸãã
ããŒããäœæãã
次ã®äŸã§ã¯ãããã¥ã¡ã³ãå
ã®ãã¹ãŠã®ç»åïŒã¿ã°ïŒãããã®ç»åã®ä»£æ¿ããã¹ã衚çŸãå®çŸ©ãããaltã屿§ã«å«ãŸããããã¹ãã§çœ®ãæããã¹ã¯ãªãããäœæããå¿
èŠããããŸãã
ãããè¡ãã«ã¯ãç»åãåé€ããã ãã§ãªããæ°ããããã¹ãããŒãã远å ããŠãããã眮ãæããå¿
èŠããããŸãã ãããè¡ãã«ã¯ãdocument.createTextNodeã¡ãœããã䜿çšããŸãã
<p> <img src="img/cat.png" alt=""> <img src="img/hat.png" alt="">.</p> <p><button onclick="replaceImages()"></button></p> <script> function replaceImages() { var images = document.body.getElementsByTagName("img"); for (var i = images.length - 1; i >= 0; i--) { var image = images[i]; if (image.alt) { var text = document.createTextNode(image.alt); image.parentNode.replaceChild(text, image); } } } </script>
è¡ãåä¿¡ãããšãcreateTextNodeã¯ã¿ã€ã3ã®DOMããŒãïŒããã¹ãïŒãæäŸããŸãããããç»é¢ã«è¡šç€ºãããããã«ããã¥ã¡ã³ãã«æ¿å
¥ã§ããŸãã
åçã®ãµã€ã¯ã«ã¯ãããŒãã®ãªã¹ãã®æåŸããå§ãŸããŸãã ããã¯ãããã¥ã¡ã³ãã倿ŽããããšãgetElementsByTagNameã¡ãœããïŒãŸãã¯childNodesããããã£ïŒã«ãã£ãŠè¿ãããããŒãã®ãªã¹ããåžžã«æŽæ°ãããããã§ãã æåããå§ããå Žåãæåã®ç»åãåé€ãããšãªã¹ãã«ãã£ãŠæåã®èŠçŽ ã倱ããããµã€ã¯ã«ã®2çªç®ã®ãã¹ã§iã1ã®å Žåããªã¹ãã®é·ãã1ã«ãªããã忢ããŸãã
ãã©ã€ããã§ã¯ãªãããŒãã®åºå®ãªã¹ããæäœããå¿
èŠãããå Žåã¯ãsliceã¡ãœããã䜿çšããŠãããå®éã®é
åã«å€æã§ããŸãã
var arrayish = {0: "", 1: "", length: 2}; var real = Array.prototype.slice.call(arrayish, 0); real.forEach(function(elt) { console.log(elt); });
document.createElementã䜿çšããŠãèŠçŽ ããŒãïŒã¿ã€ã1ïŒãäœæã§ããŸãã ã¡ãœããã¯ã¿ã°åãåããæå®ãããã¿ã€ãã®æ°ãã空ã®ããŒããè¿ããŸãã æ¬¡ã®äŸã§ã¯ãèŠçŽ ããŒããäœæããæ®ãã®åŒæ°ããã®åãšããŠäœ¿çšããeltããŒã«ãå®çŸ©ããŸãã ãã®é¢æ°ã¯ãåŒçšã«è¿œå æ
å ±ã远å ããããã«äœ¿çšãããŸãã
<blockquote id="quote"> . , , . </blockquote> <script> function elt(type) { var node = document.createElement(type); for (var i = 1; i < arguments.length; i++) { var child = arguments[i]; if (typeof child == "string") child = document.createTextNode(child); node.appendChild(child); } return node; } document.getElementById("quote").appendChild( elt("footer", "â", elt("strong", " "), ", ", elt("em", " "), ", 1950")); </script>
屿§
ãªã³ã¯å
ã®hrefãªã©ã®äžéšã®å±æ§èŠçŽ ã«ã¯ãåãååã®ãªããžã§ã¯ãããããã£ãä»ããŠã¢ã¯ã»ã¹ã§ããŸãã ããã¯ãäžè¬çã«äœ¿çšãããéãããæ°ã®æšæºå±æ§ã§å¯èœã§ãã
ãã ããHTMLã䜿çšãããšã屿§ãããŒãã«å²ãåœãŠãããšãã§ããŸãã ããã¯äŸ¿å©ã§ã ããã¥ã¡ã³ãã«è¿œå æ
å ±ãä¿åã§ããŸãã ç¬èªã®å±æ§åãèãåºãå Žåããããã¯èŠçŽ ããŒãã®ããããã£ã«ã¯å«ãŸããŸããã 代ããã«ãgetAttributeã¡ãœãããšsetAttributeã¡ãœããã䜿çšããŠããããæäœããå¿
èŠããããŸãã
<p data-classified="secret"> 00000000.</p> <p data-classified="unclassified"> .</p> <script> var paras = document.body.getElementsByTagName("p"); Array.prototype.forEach.call(paras, function(para) { if (para.getAttribute("data-classified") == "secret") para.parentNode.removeChild(para); }); </script>
çºæããã屿§ã®ååã®åã«ãdata-ããé
眮ããŠãä»ã®å±æ§ãšç«¶åããªãããã«ããããšããå§ãããŸãã ç°¡åãªäŸãšããŠãããŒã¿èšèªå±æ§ïŒèšèªïŒã§<pre>ã¿ã°ïŒãæžåŒèšå®æžã¿ãããã©ãŒãããæžã¿-ã³ãŒãããã³ãã¬ãŒã³ããã¹ãã«äœ¿çšïŒãæ€çŽ¢ããæ§æåŒ·èª¿è¡šç€ºãäœæãããã®èšèªã®ããŒã¯ãŒãã倧ãŸãã«åŒ·èª¿è¡šç€ºããããšããŸãã
function highlightCode(node, keywords) { var text = node.textContent; node.textContent = "";
highlightCode颿°ã¯ã<pre>ããŒããšãèŠçŽ ãå«ãããã°ã©ãã³ã°èšèªã®ããŒã¯ãŒãã«äžèŽããéåžžã®ã·ãŒãºã³ïŒã°ããŒãã«èšå®ãæå¹ã«ãªã£ãŠããïŒãåãå
¥ããŸãã
textContentããããã£ã䜿çšããŠããŒãã®ãã¹ãŠã®ããã¹ããååŸããç©ºã®æååã«èšå®ãããšãããŒããã¯ãªã¢ãããŸãã ããŒã¯ãŒã衚çŸã®ãã¹ãŠã®åºçŸãã«ãŒããããããã®éã«åçŽãªããã¹ãããŒãã®åœ¢åŒã§ããã¹ãã远å ããäžèŽããããã¹ãïŒããŒã¯ãŒãïŒã<strong>èŠçŽ ïŒå€ªåïŒã§å²ãã§è¿œå ããŸãã
data-language屿§ãæã€ãã¹ãŠã®<pre>èŠçŽ ãã«ãŒãåŠçããæ£ããèŠåæ§ã§åhighlightCodeãåŒã³åºãããšã«ããããã¹ãŠã®ããŒãžã³ãŒããèªåçã«åŒ·èª¿è¡šç€ºã§ããŸãã
var languages = { javascript: /\b(function|return|var)\b/g }; function highlightAllCode() { var pres = document.body.getElementsByTagName("pre"); for (var i = 0; i < pres.length; i++) { var pre = pres[i]; var lang = pre.getAttribute("data-language"); if (languages.hasOwnProperty(lang)) highlightCode(pre, languages[lang]); } }
以äžã«äŸã瀺ããŸãã
<p> , :</p> <pre data-language="javascript"> function id(x) { return x; } </pre> <script>highlightAllCode();</script>
äžè¬çã«äœ¿çšããã屿§ã§ããã¯ã©ã¹ãããããã®ååã¯JavaScriptã®ããŒã¯ãŒãã§ãã æŽå²çãªçç±ã«ãããå€ãJavaScriptå®è£
ãããŒã¯ãŒãã«äžèŽããããããã£åãåŠçã§ããªãã£ãå Žåããã®å±æ§ã¯classNameãšããããããã£ãä»ããŠå©çšã§ããŸãã getAttributeã¡ãœãããšsetAttributeã¡ãœããã䜿çšããŠãå®éã®ååãã¯ã©ã¹ãã§ã¢ã¯ã»ã¹ããããšãã§ããŸãã
èŠçŽ ã®é
眮ïŒã¬ã€ã¢ãŠãïŒ
ç°ãªãã¿ã€ãã®èŠçŽ ãç°ãªãããã«é
眮ãããŠããããšã«æ°ã¥ãããããããŸããã æ®µèœ<p>ãèŠåºã<h1>ãªã©ã®äžéšã¯ãææžã®å¹
å
šäœã«åŒã䌞ã°ãããå¥ã
ã®è¡ã«è¡šç€ºãããŸãã ãã®ãããªèŠçŽ ã¯ãããã¯èŠçŽ ãšåŒã°ããŸãã ãªã³ã¯<a>ã倪åã®ããã¹ã<strong>ãªã©ããã®ä»ã®ããã¹ãã¯ãããããå²ãããã¹ããšåãè¡ã«è¡šç€ºãããŸãã ãããã¯ã€ã³ã©ã€ã³ãšåŒã°ããŸãã
ã©ããªããã¥ã¡ã³ãã§ãããã©ãŠã¶ã¯èŠçŽ ã®é
眮ãã€ãŸã誰ãããã®ã¿ã€ããšã³ã³ãã³ãã«åºã¥ãããµã€ãºãšäœçœ®ãæã€ã¬ã€ã¢ãŠããæ§ç¯ã§ããŸãã ãã®ã¬ã€ã¢ãŠãã¯ãããã¥ã¡ã³ãã®å€èгãäœæããããã«äœ¿çšãããŸãã
èŠçŽ ã®ãµã€ãºãšäœçœ®ã¯ãJavaScriptã§ç¢ºèªã§ããŸãã offsetWidthããããã£ãšoffsetHeightããããã£ã¯ãèŠçŽ ãå ãããµã€ãºããã¯ã»ã«åäœã§ç€ºããŸãã ãã¯ã»ã«ã¯ãã©ãŠã¶ã®åºæ¬çãªæž¬å®åäœã§ãããéåžžã¯ç»é¢äžã®æå°ãã€ã³ãã®ãµã€ãºã«å¯Ÿå¿ããŠããŸãã åæ§ã«ãclientWidthãšclientHeightã¯èŠçŽ ã®å
åŽã®ãµã€ãºãæäŸããå¢çç·ïŒãŸãã¯ãäžéšã®èšãæ¹ã§ã¯çžç³ïŒãã«ãŠã³ãããŸããã
<p style="border: 3px solid red"> </p> <script> var para = document.body.getElementsByTagName("p")[0]; console.log("clientHeight:", para.clientHeight); console.log("offsetHeight:", para.offsetHeight); </script>
ç»é¢äžã®èŠçŽ ã®æ£ç¢ºãªäœçœ®ãèŠã€ããæã广çãªæ¹æ³ã¯ãgetBoundingClientRectã¡ãœããã§ãã ç»é¢ã®å·Šäžé
ã«å¯ŸããèŠçŽ ã®äœçœ®ããã¯ã»ã«åäœã§å«ãããããã£topãbottomãleftãããã³rightïŒtopãbottomãleftãããã³rightïŒãæã€ãªããžã§ã¯ããè¿ããŸãã ææžå
šäœã«ã€ããŠãã®ããŒã¿ãååŸããå¿
èŠãããå ŽåãçŸåšã®ã¹ã¯ããŒã«äœçœ®ã远å ããå¿
èŠããããŸããããã¯ãã°ããŒãã«å€æ°pageXOffsetããã³pageYOffsetã«å«ãŸããŠããŸãã
ããã¥ã¡ã³ãã®è§£æã¯é£ããäœæ¥ã§ãã ããã©ãŒãã³ã¹äžã®çç±ããããã©ãŠã¶ãšã³ãžã³ã¯ãããã¥ã¡ã³ãã倿Žããããã³ã«ããã¥ã¡ã³ããåæ§ç¯ããã®ã§ã¯ãªããéåžžã«é·ãåŸ
æ©ããŸãã ããã¯ã©ã®ããã«å¯èœã§ããã ããã¥ã¡ã³ãã倿ŽããJavaScriptããã°ã©ã ãçµäºãããšããã©ãŠã¶ãŒã¯ããŒãžã®æ°ããã¬ã€ã¢ãŠããèšç®ããŠã倿Žãããããã¥ã¡ã³ããç»é¢ã«è¡šç€ºããå¿
èŠããããŸãã ããã°ã©ã ãäœãã®äœçœ®ãŸãã¯ãµã€ãºãèŠæ±ããoffsetHeightåã®ããããã£ãèªã¿åãããgetBoundingClientRectãåŒã³åºãå Žåãæ£ããæ
å ±ãæäŸããããã«ã¬ã€ã¢ãŠããèšç®ããå¿
èŠããããŸãã
宿çã«DOMã¬ã€ã¢ãŠããèªã¿åããDOMã倿Žããããã°ã©ã ã«ããããã©ãŠã¶ãŒã¯ã¬ã€ã¢ãŠããäœåºŠãåã«ãŠã³ããããããåäœãé
ããªããŸãã æ¬¡ã®äŸã§ã¯ã2000ãã¯ã»ã«å¹
ã®Xæåã®è¡ãæ§ç¯ããã©ã³ã¿ã€ã ãæž¬å®ãã2ã€ã®ç°ãªãããã°ã©ã ããããŸãã
<p><span id="one"></span></p> <p><span id="two"></span></p> <script> function time(name, action) { var start = Date.now();
ã¹ã¿ã€ã«
ããŸããŸãªHTMLèŠçŽ ã®åäœãç°ãªãããšãããããŸããã ãããã¯ãšããŠè¡šç€ºããããã®ãããã°ãçµã¿èŸŒã¿ã®ãã®ããããŸãã ããã€ãã¯èŠèŠçãªã¹ã¿ã€ã«ã远å ããŸã-ã®ãããª
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.
angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.
angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.
angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.
angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.
angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.
angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.
angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.
angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.
angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.
angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.
angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.
angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); // <p> // â 4 console.log(count(".animal")); // animal // â 2 console.log(count("p .animal")); // animal <p> // â 2 console.log(count("p > .animal")); // <p> // â 1 </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.

angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> /* */ table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { // } document.body.appendChild(buildTable(MOUNTAINS)); </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { // } console.log(byTagName(document.body, "h1").length); // â 1 console.log(byTagName(document.body, "span").length); // â 3 var para = document.querySelector("p"); console.log(byTagName(para, "span").length); // â 2 </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); // Your code here. </script>
.
, , . , , , . style ():
<p><a href="."> </a></p> <p><a href="." style="color: green"> </a></p>
style (color), . : âcolor: red; border: noneâ.
. , display , .
<strong></strong>, <strong style="display: block"> </strong>, <strong style="display: none"> </strong>.
, â display: none . . , .
JavaScript style. , . â , - .
<p id="para" style="color: purple"> </p> <script> var para = document.getElementById("para"); console.log(para.style.color); para.style.color = "magenta"; </script>
, font-family. JavaScript ( style["font-family"]), , : style.fontFamily
HTML CSS (Cascading Style Sheets, ). â . :
<style> strong { font-style: italic; color: gray; } </style> <p> <strong> strong</strong> .</p>
«» , . , , , font-style .
, . font-weight: normal, , , . , style, .
CSS . .abc , âabcâ. #xyz id âxyzâ ( id ).
.subtle { color: gray; font-size: 80%; } #header { background: blue; color: white; } /* p, a b, id main */ pab#main { margin-bottom: 20px; }
, . , , . , pa , p .a, .
p > a {âŠ}
, .
pa {âŠ}
, , .
. , 2-3 . (, , ) â - DOM.
querySelectorAll, document, -, , , .
<p> <span class="animal"></span></p> <p> </p> <p> <span class="character"> <span class="animal"> </span></span></p> <p> .</p> <script> function count(selector) { return document.querySelectorAll(selector).length; } console.log(count("p")); </script>
getElementsByTagName, querySelectorAll . , .
querySelector ( All) . , . , null, .
position . static, , . relative, , top left . absolute, «» â , . , left top , position static. , .
. , .
<p style="text-align: center"> <img src="img/cat.png" style="position: relative"> </p> <script> var cat = document.querySelector("img"); var angle = 0, lastTime = null; function animate(time) { if (lastTime != null) angle += (time - lastTime) * 0.001; lastTime = time; cat.style.top = (Math.sin(angle) * 20) + "px"; cat.style.left = (Math.cos(angle) * 200) + "px"; requestAnimationFrame(animate); } requestAnimationFrame(animate); </script>
position: relative. top left , .
requestAnimationFrame animate , . animate requestAnimationFrame, . ( ) , 60 , .
DOM , . JavaScript, . requestAnimationFrame â , , , .
, ( lastTime), , . , , , .
Math.cos Math.sin. , , .
Math.cos Math.sin , (0, 0) . , 0 , , 2Ï ( 6.28) . Math.cos x , , Math.sin y. ( ) , 2Ï 0, â , a+2Ï , a.
angle , animation. image. top Math.sin 20 â . left Math.cos 200, .
. px , , ( , ems ). . â 0, .
JavaScript DOM. , JavaScript . DOM , . parentNode childNodes, .
, , - . , , color display. JavaScript style.
6. HTML . HTML :
<table> <tr> <th>name</th> <th>height</th> <th>country</th> </tr> <tr> <td>Kilimanjaro</td> <td>5895</td> <td>Tanzania</td> </tr> </table>
. : , .
, 6, MOUNTAINS.
buildTable, , , DOM, . , , , . Object.keys, , .
, , style.textAlign "right".
<style> table { border-collapse: collapse; } td, th { border: 1px solid black; padding: 3px 8px; } th { text-align: left; } </style> <script> function buildTable(data) { </script>
getElementsByTagName . , ( ) , .
, tagName. , . toLowerCase toUpperCase.
<h1> <span>span</span> .</h1> <p> <span></span>, <span></span> spans.</p> <script> function byTagName(node, tagName) { </script>
, 
.
. - .
, . top left . , position.
<img src="img/cat.png" id="cat" style="position: absolute"> <img src="img/hat.png" id="hat" style="position: absolute"> <script> var cat = document.querySelector("#cat"); var hat = document.querySelector("#hat"); </script>