Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions DOM.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function addText() {
document.getElementById("para1").textContent = "We are coders!";
}

function changeText() {
document.getElementById("para1").innerHTML = "Developers for life!";
}

function addImage() {
let image = new Image(200, 200);
image.src = "tech.jpg";
document.getElementById("para2").appendChild(image);
}

function changeColor() {
document.getElementById("para1").style.color = "brown";
}

function fontSize() {
document.getElementById("para1").style.fontSize = "40px";
}

function hideImage() {
document.getElementById("para2").textContent = "";
}








30 changes: 30 additions & 0 deletions TOC.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Table of Contents</title>

</head>
<body>
<div id="toc">
<h3>Table of Contents</h3>
</div>
<hr/>
<div id="contents">
<h1>Fruits</h1>
<h2>Red Fruits</h2>
<h3>Apple</h3>
<h3>Raspberry</h3>
<h2>Orange Fruits</h2>
<h3>Orange</h3>
<h3>Tangerine</h3>
<h1>Vegetables</h1>
<h2>Vegetables Which Are Actually Fruits</h2>
<h3>Tomato</h3>
<h3>Eggplant</h3>

</div>
<script src="toc.js" ></script>
</body>
</html>
26 changes: 26 additions & 0 deletions about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>About me</TITLE>

<script src="main.js"></script>
</HEAD>
<body id="font">

<button type="button" onclick="changeFont()">font style</button>
<button type="button" onclick="changeColor()">change color</button>
<h1>About Me</h1>
<span>
<ul id="list">
<li>Nickname: hinz</li>
<li>Favorites: music, pizza, The Office</li>
<li>Hometown: Bear </li>
<li>Random Fact: Brown is my favorite color.</li>
</ul>
</span>



</body>
</HTML>
38 changes: 38 additions & 0 deletions js-dom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html>
<head>
<title>DOM lab</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){
$('#btn1').on("click",function(e){
$('#myImg').toggle('slow');
});
});
</script>
</head>
<body>


<p id="para1" style="color: red; font-size: 40px;">Developers for life!</p>

<p id="Para2"></p>

<img id="myImg" src="http://placeimg.com/200/200/arch" alt="architecture">
<p id="demo"></p>

<button type="button" id="btn1">Show/Hide Image</button>

<script>
function myFunction() {
var x = document.getElementById("myImg").src;
document.getElementById("demo").innerHTML = x;
document.getElementById("para1").style.fontSize = "40px";

}
</script>
</body>

</html>

8 changes: 8 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

function changeFont() {
document.getElementById("font").style.fontFamily = "Arial,sans-serif";
}

function changeColor() {
document.getElementById("list").style.color = "green";
}
49 changes: 49 additions & 0 deletions toc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
var c = function() {
return({
log: function(msg) {
consoleDiv = document.getElementById('console');
para = document.createElement('p');
text = document.createTextNode(msg);
para.appendChild(text);
consoleDiv.appendChild(para);
}
});
}();

window.onload = function () {
var toc = "";
var level = 0;
var maxLevel = 3;

document.getElementById("contents").innerHTML =
document.getElementById("contents").innerHTML.replace(
/<h([\d])>([^<]+)<\/h([\d])>/gi,
function (str, openLevel, titleText, closeLevel) {
if (openLevel != closeLevel) {
c.log(openLevel)
return str + ' - ' + openLevel;
}

if (openLevel > level) {
toc += (new Array(openLevel - level + 1)).join("<ol>");
} else if (openLevel < level) {
toc += (new Array(level - openLevel + 1)).join("</ol>");
}

level = parseInt(openLevel);

var anchor = titleText.replace(/ /g, "_");
toc += "<li><a href=\"#" + anchor + "\">" + titleText
+ "</a></li>";

return "<h" + openLevel + "><a name=\"" + anchor + "\">"
+ titleText + "</a></h" + closeLevel + ">";
}
);

if (level) {
toc += (new Array(level + 1)).join("</ol>");
}

document.getElementById("toc").innerHTML += toc;
};