衚珟力豊かなJavaScriptドキュメントオブゞェクトモデル

内容




ブラりザで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, "")); // → true 


テキストノヌドプロパティ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 = ""; //   var match, pos = 0; while (match = keywords.exec(text)) { var before = text.slice(pos, match.index); node.appendChild(document.createTextNode(before)); var strong = document.createElement("strong"); strong.appendChild(document.createTextNode(match[0])); node.appendChild(strong); pos = keywords.lastIndex; } var after = text.slice(pos); node.appendChild(document.createTextNode(after)); } 


highlightCode関数は、<pre>ノヌドず、芁玠を含むプログラミング蚀語のキヌワヌドに䞀臎する通垞のシヌズングロヌバル蚭定が有効になっおいるを受け入れたす。

textContentプロパティを䜿甚しおノヌドのすべおのテキストを取埗し、空の文字列に蚭定するず、ノヌドがクリアされたす。 キヌワヌド衚珟のすべおの出珟をルヌプし、それらの間に単玔なテキストノヌドの圢匏でテキストを远加し、䞀臎するテキストキヌワヌドを<strong>芁玠倪字で囲んで远加したす。

data-language属性を持぀すべおの<pre>芁玠をルヌプ凊理し、正しい芏則性で各highlightCodeを呌び出すこずにより、すべおのペヌゞコヌドを自動的に匷調衚瀺できたす。

 var languages = { javascript: /\b(function|return|var)\b/g /* 
 etc */ }; 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(); //     action(); console.log(name, "", Date.now() - start, "ms"); } time("", function() { var target = document.getElementById("one"); while (target.offsetWidth < 2000) target.appendChild(document.createTextNode("X")); }); // →   32 ms time("", function() { var target = document.getElementById("two"); target.appendChild(document.createTextNode("XXXXX")); var total = Math.ceil(2000 / (target.offsetWidth / 5)); for (var i = 5; i < total; i++) target.appendChild(document.createTextNode("X")); }); // →   1 ms </script> 


スタむル


さたざたな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")); // <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")); // <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")); // <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")); // <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")); // <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>

Source: https://habr.com/ru/post/J243815/


All Articles