<img id="img1">Include this line in your CSS file:
img { width: 200px; background-color: #C0C0C0; }Answer:
<!DOCTYPE html> <!-- Source code file: index.html Script for Exercise 1 --> <html lang="en"> <head> <meta charset="UTF-8"> <title>Exercise 1</title> <link rel="stylesheet" href="styles.css"> <script src="script.js"></script> </head> <body> <h1>Exercise 1</h1> <img id="img1"><br> <input type="radio" id="ele" name="animal" value="elephant"> Elephant<br> <input type="radio" id="lio" name="animal" value="lion"> Lion<br> <input type="radio" id="mon" name="animal" value="monkey"> Monkey<br> <input type="radio" id="rhi" name="animal" value="rhinoceros"> Rhinoceros </body> </html> --------------------------------------------------- /* Source code file: styles.css Stylesheet for Exercise 1 */ body { font: 120% verdana, sans-serif; } img { width:200px; height: 150px; background-color: #C0C0C0;} --------------------------------------------------- // Source code file: script.js // Script for Exercise 1. function showAnimal(e) { var animalName = e.target.value; var imageName = "images/" + animalName + ".jpg"; document.getElementById("img1").src = imageName; } function init( ) { var radEle = document.getElementById("ele"); var radLio = document.getElementById("lio"); var radMon = document.getElementById("mon"); var radRhi = document.getElementById("rhi"); radEle.addEventListener("click", showAnimal); radLio.addEventListener("click", showAnimal); radMon.addEventListener("click", showAnimal); radRhi.addEventListener("click", showAnimal); } window.addEventListener("load", init); ===================================================
=================================================== <!DOCTYPE html> <!-- Source Code File: index.html HTML file for Exercise 2 --> <html lang="en"> <head> <meta charset="UTF-8"> <title>Exercise 2</title> <link rel="stylesheet" href="styles.css"> <script src="script.js"></script> </head> <body> <h1>Exercise 2</h1> <img id="img1"><br> <select id="sel1"> <option value="elephant">Elephant</option> <option value="lion">Lion</option> <option value="monkey">Monkey</option> <option value="rhinoceros">Rhinoceros</option> </select> </body> </html> ----------------------------------------------------- /* Source Code File: styles.css Stylesheet for Exercise 2 */ body { font: 120% verdana, sans-serif; } img { width:200px; height: 150px; background-color: #C0C0C0;} ----------------------------------------------------- // Source Code File: script.js // Script for Exercise 2. function showAnimal( ) { var animalName = document.getElementById("sel1").value; var imageName = "images/" + animalName + ".jpg"; document.getElementById("img1").src = imageName; } function init( ) { var select1 = document.getElementById("sel1") select1.addEventListener("change", showAnimal); } window.addEventListener("load", init); =====================================================
===================================================== // Source code file: script.js // Script for Exercise 3. window.addEventListener("load", ( ) => { var select1 = document.getElementById("sel1"); select1.addEventListener("change", ( ) => { var animalName = document.getElementById("sel1").value; var imageName = "images/" + animalName + ".jpg"; document.getElementById("img1").src = imageName; }); }); =====================================================
<p>Lorem ipsum odor amet, consectetuer adipiscing elit. Maecenas ipsum ligula tempor lorem mus integer. Platea nisi fusce placerat mus magnis ipsum. Ipsum sed platea tincidunt, magnis et commodo. Orci mattis tempus amet himenaeos lobortis dis iaculis accumsan. Id suscipit proin laoreet vel eleifend morbi. Pharetra erat id egestas ultricies ad tempus feugiat aliquet eu. Phasellus per vestibulum ut curabitur himenaeos consequat senectus quisque magnis. Fusce posuere vulputate sem egestas cursus dignissim duis.</p>Define a CSS class that sets the span element to bold, red, and Chiller font. Apply this class to five words in the paragraph.
=============================================== <!DOCTYPE html> <!-- Source Code File: index.html HTML code for Exercise 4 --> <html lang="en"> <head> <meta charset="UTF-8"> <title>Exercise 4</title> <link rel="stylesheet" href="styles.css"> </head> <body> <h1>Exercise 4</h1> <h2>Lorem Ipsum Text</h2> <p>Lorem ipsum odor amet, consectetuer adipiscing elit. Maecenas ipsum ligula tempor lorem mus integer. Platea nisi fusce <span class="r">placerat</span> mus magnis ipsum. Ipsum sed platea tincidunt, magnis et commodo. Orci mattis tempus amet himenaeos lobortis dis iaculis accumsan. Id suscipit proin <span class="r">laoreet</span> vel eleifend morbi. Pharetra erat id egestas ultricies ad tempus feugiat aliquet eu. Phasellus per <span class="r">vestibulum</span> ut curabitur himenaeos consequat senectus quisque magnis. Fusce posuere vulputate sem egestas cursus dignissim <span class="r">duis</span>.</p> </body> </html> ----------------------------------------------- /* Source Code File: styles.css Exercise 4 */ /* Define CSS Class */ .r { font: bold 200% Chiller, sans-serif; color: red; } ===============================================
h1 p td li span
<body> <div id="content"> <h1>Sample HTML Page</h1> <p class="info">Lorum ipsum dolor sit amet.</p> <p>Lorum ipsum dolor <a href="#">sit</a> amet.</p> </div> <div id="nav"> <ul> <li><a href="#" class="intro">Item 1<a></li> <li><a href="#">Item 2</li> <li><a href="#">Item 3</li> </ul> </div> <div id="footer"> Lorum ipsum dolor <a href="#">sit</a> amet. </div> </body>Here are some CSS selectors:
li { color: blue; }
.intro { font-weight: bold; } p.intro { color: red; } a.intro { color: green; }
#nav { color: blue; }
li a { color: green; } ol ol { list-style-type: lower-roman; } #nav a { color: red; } #nav ul li a { color: green; }
* { margin: 0px; padding: 0px; }
div > em { color: blue; }
h2 + h3 { margin: -1em; }
img[src="small.gif"] { border: 1px solid #000000; }
p::first-line { color: red; } p::first-letter { font-size: 200%; font-weight: bold; }
// querySelector Statement: var paragraph = document.querySelector("#p1"); // JavaScript Statement var paragraph = document.getElementById("p1"); // querySelector Statement: var paragraph = document.querySelector("p"); // JavaScript statement: var paragraph = document.getElementsByTagName("p")[0]; // querySelector Statement: var paragraph = document.querySelector(".red"); // JavaScript statement: var paragraph = document.getElementsByClassName("red")[0]; // querySelectorAll Statement: var paragraph = document.querySelectorAll("p"); // JavaScript statement: var paragraph = document.getElementsByTagName("p"); // querySelectorAll Statement: var paragraph = document.querySelectorAll(".red"); // JavaScript statement: var paragraph = document.getElementsByClassName("red");
<body></body>write JavaScript statement that changes the background-color style of the body to silver when the body is clicked. There is no defined id so you can't use document.getElementById.
<body> <p>Lorem ipsum.</p> <p>In eu blandit velit.</p> <p>Proin turpis erat, porta dignissim dapibus in, rhoncus et diam. Sed id ante mattis.</p> <p>Suspendisse.</p> <p>Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sed nunc nisi.</p> <button>Replace Paragraphs.</button> </body>Write an event listener for the button so that all paragraphs with length > 30 characters are replaced with the string "Paragraph too long. You've been replaced."
We will discuss this section on Wednesday, Dec 19.
<body> <h1>Planetary Outpost Status Summaries</h1> <ol> <li>Green Planet<br> All is well.</li> <li class="redtext">Red Planet<br> All systems A-OK.</p> </ol> <h2>Number of Planets</h2> <p id="para">3</p> </body>
+--------- body ---------+ | / \ | | / \ | h1 ol h2 p / \ li li
body h1 Planetary Outpost Status Summaries ol li Green Planet<br>All is well. li Red Planet<br>All systems A-OK. h2 Number of Planets p 3
// Return the HTML element with id="123" document.getElementById("123") // Return array of all HTML elements with // tag name input document.getElementsByTagName("input") // Return array of all HTML elements that // implement the CSS class .redtext document.getElementsByClassName("redtext") // Return the first HTML li tag that // implements the class .redtext. document.querySelector("li .redtext") // Return array of all HTML li tags that // implement the class .redtext document.querySelectorAll("li .redtext")
innerHTML nodeName firstChild lastChild childNodes previousSibling nextSibling
element.attributeName = "HTMLAttributeValue"; element.style.styleName = "cssStyleValue";
document.createElement(tag_name); document.removeChild(element); document.appendChild(element); document.replaceChild(oldElement, newElement);
For the Planetary Outpost Status Summaries page, show the output in this element at the end of the document:
<p id="output"></p>
<!DOCTYPE html> <!-- Source code file: index.html --> <html lang="en"> <head> <meta charset="UTF-8"> <title>Planetary Output Summaries</title> <script src="script.js"></script> </head> <body> <h1>Planetary Outpost Status Summaries</h1> <ol> <li>Green Planet<br> All is well.</li> <li class="redtext">Red Planet<br> All systems A-OK.</p> </ol> <h2>Number of Planets</h2> <p id="para">3</p> </body> </html>
<body></body>
This is a test.
Name | Height | Country |
---|---|---|
Kilimanjaro | 5895 | Tanzania |