|
3 | 3 | /*
|
4 | 4 | WooHoo, you got so far on your first day! Great! But we still have more things for you.
|
5 | 5 | First of all, go to index.html file and replace our script from level2.js to current
|
6 |
| - file - level3.js |
| 6 | + file - level3.js. |
| 7 | + PS: if you want few js files to be used simply add more scripts with those files. |
7 | 8 | */
|
8 | 9 |
|
9 | 10 | /*
|
|
19 | 20 | meta information, title and link to css files. <Body> contains our actual content.
|
20 | 21 | Tags has a set of names which you can find here http://htmldog.com/references/html/tags/
|
21 | 22 |
|
22 |
| - Any tag also can have different properties (<div class="settings"></div> - tag div |
23 |
| - has a property class, that has name = 'settings'). |
| 23 | + Any tag also can have different attributes (<div class="settings"></div> - tag div |
| 24 | + has a attribute class, that has name = 'settings'). |
24 | 25 |
|
25 | 26 | CSS:
|
26 | 27 | Stands for Cascading Style Sheets. CSS describes how HTML elements are to be
|
27 | 28 | displayed on screen. As you can see in css file when we need to target any element
|
28 |
| - we can simply refer to the tag itself (footer{color: white;}), or to any property (class |
| 29 | + we can simply refer to the tag itself (footer{color: white;}), or to any attribute (class |
29 | 30 | via '.settings', id via '#logo' etc). The list of css properties is huge, you can check
|
30 | 31 | on it here https://www.w3.org/TR/CSS21/propidx.html but don't worry, you don't need to
|
31 | 32 | remember it all.
|
|
41 | 42 |
|
42 | 43 |
|
43 | 44 | /*
|
| 45 | + Accessing page objects. |
| 46 | + DOM - Stands for Document Object Model. It defines the logical structure of documents |
| 47 | + and the way a document is accessed and manipulated. So let's get things from the page |
| 48 | + and play around. |
| 49 | + To find and get nods(page elements) we can use querySelector one of the functions of |
| 50 | + JavaScript (in old browsers it might not work, in this case getElementById, |
| 51 | + getElementsByTagsName etc should be used). |
| 52 | + Let's get our twitter from the page. |
| 53 | + Example: |
| 54 | + var ourTwitter = document.querySelector('.twitter'); |
| 55 | + //we can store it in variable so we can use it after |
| 56 | + */ |
| 57 | + |
| 58 | +//TODO: Now it's your turn - get the h1 tag from the page and store it into variable named |
| 59 | +//ourTitle. console.log it and see what you will get. |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | +/* |
| 71 | + Getting a set of elements |
| 72 | + We also can get all elements with the same tag. So in the footer we have <ul>(unordered list) |
| 73 | + with 3 <li>(lists) inside. Let's get all of them |
| 74 | + Example: |
| 75 | + var mediaLinks = document.querySelectorAll('li'); //will get all <li> from the page |
| 76 | + */ |
| 77 | + |
| 78 | + |
| 79 | +//TODO: get all <li> elements from the page in variable named mediaLinks |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | +//TODO: now console.log mediaLinks.length |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | +//TODO: do you still remember arrays that we had in previous sections? Using this knowladge |
| 90 | +//itirate through whole meadiaLinks items and print them out. |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | +/* |
| 101 | + Ok, so far so good. But what if we need only content of our 'h1' tag? We have |
| 102 | + another property for it - .innerHTML |
| 103 | + Example: |
| 104 | + ourTwitter.innerHTML; |
| 105 | + //we will get text '@NodeGirlsSydney' |
| 106 | + */ |
| 107 | + |
| 108 | + |
| 109 | +//TODO: get the content of 'h1' element and console.log it |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | +/* |
| 121 | + Change content |
| 122 | + Using same property .innerHTML we can change content of the tags. |
| 123 | + Example: |
| 124 | + ourTwitter.innerHTML = '@ButenkoMe'; |
| 125 | + console.log(ourTwitter.innerHTML); |
| 126 | + //guess what we will see on the page and in console? |
| 127 | + */ |
| 128 | + |
| 129 | + |
| 130 | +//TODO: change content of the 'h1' on anything you like |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | +/* |
| 137 | + Changing properties. |
| 138 | + We also can change and set attributes to our elements. |
| 139 | + Example: |
| 140 | + var ourTwitter = document.querySelector('.twitter'); |
| 141 | + ourTwitter.id = "surprise"; |
| 142 | + */ |
| 143 | + |
44 | 144 |
|
| 145 | +//TODO: replace 'src' attribute for our img tag on "img/kittens.jpeg" |
| 146 | + |
| 147 | + |
| 148 | + |
| 149 | + |
| 150 | + |
| 151 | +/* |
| 152 | + Accessing and changing styles |
| 153 | + So, let's do some css changes. We can do it with help of '.style' property and then |
| 154 | + giving the css property as we use them in css file, the only change is - if is css |
| 155 | + property name has '-' in the name (like font-size etc) then dash will be deleted and |
| 156 | + next word starts with capital (fontSize) - this way of naming calls CamelCase :) |
| 157 | + Example: |
| 158 | + var ourTwitter = document.querySelector('.twitter'); |
| 159 | + ourTwitter.style.backgroundColor = 'white'; |
45 | 160 | */
|
46 | 161 |
|
47 | 162 |
|
| 163 | +//TODO: get any element on the page and change some styles for it |
| 164 | + |
| 165 | + |
| 166 | + |
| 167 | + |
| 168 | + |
| 169 | + |
| 170 | + |
| 171 | +/* |
| 172 | + Creating new nodes (elements) |
| 173 | + The document object also provides ways to create nodes from scratch: |
| 174 | + document.createElement(tagName); |
| 175 | + document.createTextNode(text); |
| 176 | + document.appendChild(); |
| 177 | + Example: |
| 178 | + var pageNode = document.querySelector('body')[0]; |
| 179 | + var newParagraph = document.createElement('p'); |
| 180 | + var paragraphText = document.createTextNode('Squee!'); |
| 181 | + newParagraph.appendChild(paragraphText); |
| 182 | + pageNode.appendChild(newParagraph); |
| 183 | + */ |
| 184 | + |
| 185 | + |
| 186 | +//TODO: Well, do you still have kittens on your screen? I like both logo and kittens. |
| 187 | +//Let's create a new image with source logo and put it into header. |
| 188 | +//PS: you also can give styles to the new node that you create. |
| 189 | + |
| 190 | + |
| 191 | + |
| 192 | + |
| 193 | + |
| 194 | + |
| 195 | + |
| 196 | + |
| 197 | + |
| 198 | + |
| 199 | + |
| 200 | + |
| 201 | + |
| 202 | + |
| 203 | + |
| 204 | + |
| 205 | + |
| 206 | + |
| 207 | +//////////////////////////////////////////////////////////////////////// |
| 208 | +//Congratulations! You have finished Part 1 of JavaScript Basics! // |
| 209 | +// Stand up, stretch your legs, celebrate your achievement. // |
| 210 | +// I believe you deserve on some sweets today! // |
| 211 | +//////////////////////////////////////////////////////////////////////// |
48 | 212 |
|
49 | 213 |
|
0 commit comments