diff --git a/lib/styles.css b/CSS/styles.css similarity index 100% rename from lib/styles.css rename to CSS/styles.css diff --git a/JS/main.js b/JS/main.js new file mode 100644 index 0000000..2d168d5 --- /dev/null +++ b/JS/main.js @@ -0,0 +1,53 @@ +//Style body element with 'Arial, sans-serif' font family +const bodyTag = document.querySelector('body'); +bodyTag.style.fontFamily = "Arial, sans-serif"; + +//Create variable for list items +const listItems = document.querySelectorAll('li'); + +//Iterate through each list item and change color to purple! +for (let i = 0; i < listItems.length; i++) { + const thisLi = listItems[i]; + thisLi.style.color = "purple"; +} + +//Select list items to replace +//Change 1st List Item +const oldNickname = document.querySelector("li:first-child"); +//Create new list item element to replace the old one +const newNickname = document.createElement('li'); +newNickname.innerHTML = '
  • Stephanie
  • '; +//Target parent element of the target child & apply changes to child +oldNickname.parentNode.replaceChild(newNickname, oldNickname); + +//Change 2nd List Item +const oldFavorites = document.querySelector("li:nth-of-type(2)"); +//Create new list item element to replace the old one +const newFavorites = document.createElement('li'); +newFavorites.innerHTML = '
  • Favorites: Jazz music, filet-mignon, Office Space
  • '; +//Target parent element of the target child & apply changes to child +oldFavorites.parentNode.replaceChild(newFavorites, oldFavorites); + +//Change 3rd List Item +const oldHometown = document.querySelector("li:nth-of-type(3)"); +//Create new list item element to replace the old one +const newHometown = document.createElement('li'); +newHometown.innerHTML = '
  • Hometown: Middletown
  • '; +//Target parent element of the target child & apply changes to child +oldHometown.parentNode.replaceChild(newHometown, oldHometown); + +//Change Last List Item +const oldRandom = document.querySelector("li:nth-of-type(4)"); +//Create new list item element to replace the old one +const newRandom = document.createElement('li'); +newRandom.innerHTML = '
  • Random Fact: I have traveled to Japan!
  • '; +//Target parent element of the target child & apply changes to child +oldRandom.parentNode.replaceChild(newRandom, oldRandom); + +//Style the
  • 's to a color of my choosing +document.getElementById("aboutList").style.color = "turquoise"; + +//Create img element to hold new image +let myImg = new Image(200, 215); +myImg.src = 'myPhoto.jpg'; +document.body.appendChild(myImg); diff --git a/JS/myScript_1.js b/JS/myScript_1.js new file mode 100644 index 0000000..eee9817 --- /dev/null +++ b/JS/myScript_1.js @@ -0,0 +1,42 @@ + +const msgBothPars = "We are coders!"; +const msgFirstPar = "Developers for life!"; + +//Insert text to both paragraphs +let bothPars = document.querySelectorAll(".pars"); + +for (let i = 0; i < bothPars.length; i++) { + const thisPars = bothPars[i]; + thisPars.innerText = msgBothPars; +}; + +//Change text content & font size of first paragraph +let parFirst = document.getElementById("parOne"); +parOne.innerText = msgFirstPar; +parOne.style.fontSize = "40px"; + +//Assign image to variable +let imageHtml = ` +drawing of diverse people in tech +`; + +//Place image in body of HTML +let bodyTag = document.querySelector('body'); +bodyTag.innerHTML += imageHtml; + +//Change text color in body to purple +bodyTag.style.color = "purple"; + +//Create functionality to hide/display image with button +function buttonAction() { + const targetImage = document.querySelector(".divTechImg"); + const curStatus = targetImage.style.visibility; + + if(curStatus == "hidden"){ + targetImage.style.visibility = "visible"; + } else { + targetImage.style.visibility = "hidden"; + } +} + + diff --git a/lib/script.js b/JS/script.js similarity index 80% rename from lib/script.js rename to JS/script.js index 51e5df8..1575cae 100644 --- a/lib/script.js +++ b/JS/script.js @@ -40,3 +40,8 @@ var characters = [ contribution: "What did/do I do?" }, ]; +// Set the innerHTML property: HTMLElementObject.innerHTML = text +// Change the HTML content, URL, and target of a link: +// document.getElementById("myAnchor").innerHTML = "W3Schools"; +// + diff --git a/JS/table-of-contents.js b/JS/table-of-contents.js new file mode 100644 index 0000000..9d0133d --- /dev/null +++ b/JS/table-of-contents.js @@ -0,0 +1,48 @@ + +//selects elements h1, h2 & h3 and saves them to a variable 'toc' +let toc = document.querySelectorAll('h1, h2, h3'); + +//creates an unordered list +let ul = document.createElement('ul'); +ul.setAttribute("class", "main"); + +//places the list inside the div element +document.querySelector('div').appendChild(ul); + +let tocItem; +let content; +let oldList; + +//iterate through the elements on the page +for (let i = 1; i < toc.length; i++) { + if (toc[i].nodeName == 'H2') { + ul = document.createElement('ul'); + ul.setAttribute("class", "sub1"); + document.querySelector('ul').appendChild(ul); + tocItem = document.createElement('li'); // creates a list item element + content = document.createTextNode(toc[i].textContent); // creates a text node w content + tocItem.appendChild(content); //appends the content to the list item + ul.appendChild(tocItem); //appends the list item to the unordered list + } else if (toc[i].nodeName == 'H3' && toc[i-1].nodeName == 'H2') { + ul = document.createElement('ul'); + ul.setAttribute("class", "sub2"); + tocItem.appendChild(ul); + tocItem = document.createElement('li'); + content = document.createTextNode(toc[i].textContent); + tocItem.appendChild(content); + ul.appendChild(tocItem); + } else if (toc[i].nodeName == 'H3' && toc[i-1].nodeName == 'H3') { + oldList = tocItem; + tocItem = document.createElement('li'); + content = document.createTextNode(toc[i].textContent); + tocItem.appendChild(content); + oldList.appendChild(tocItem); + } else { + li = document.createElement('li'); + content = document.createTextNode(toc[i].textContent); + li.appendChild(content); + document.querySelector('ul').appendChild(li); + } +} + +//referenced: https://www.w3schools.com/jsref/met_document_createtextnode.asp diff --git a/about.html b/about.html new file mode 100644 index 0000000..c7ecfb9 --- /dev/null +++ b/about.html @@ -0,0 +1,27 @@ + + + + + + + _About Me_ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/js-dom-lab.md b/js-dom-lab.md index 619bc3c..146a933 100644 --- a/js-dom-lab.md +++ b/js-dom-lab.md @@ -1,76 +1,67 @@ ![code differently](https://user-images.githubusercontent.com/54545904/91590200-f82ec600-e928-11ea-9433-eea450388abf.png) - - ## JavaScript and the DOM Lab - - - - ### The Set-Up - - Fork and clone this repository locally and in Visual Studio Code - Push up your changes to the remote repository - - ### Tasks #### Part One -1. Create an HTML file called `js-dom.html` +1. - Create an HTML file called `js-dom.html` - - Must have global HTML document structure + - Must have global HTML document structure -2. Add two `

    ` elements without content. +2. - Add two `

    ` elements without content. -3. Give each `

    ` element an `id` and value +3. - Give each `

    ` element an `id` and value 4. Stage, commit, and push changes. Let Git be on your team. 5. Create scripts for each exercise: - - Write a script to add "We are coders!" to the `

    ` element. + - Write a script to add "We are coders!" to the `

    ` element. + + - Find the _first_ `

    ` element and change its text to "Developers for life!" + + - Add an image to that e HTML document using DOM methods + + > Stage, commit, and push changes. Let Git be on your team. - - Find the *first* `

    ` element and change its text to "Developers for life!" + - Write a script to change the color of the text from black to your favorite color - - Add an image to the HTML document using DOM methods + - Add a script to change the font size of the first `

    ` element to `40px` - > Stage, commit, and push changes. Let Git be on your team. + > Stage, commit, and push changes. Let Git be on your team. - - Write a script to change the color of the text from black to your favorite color + - Add a button to the HTML document - - Add a script to change the font size of the first `

    ` element to `40px` - - > Stage, commit, and push changes. Let Git be on your team. - - - Add a button to the HTML document - - - Add a script that hides the image when the button is clicked - - > Stage, commit, and push changes. Let Git be on your team. + - Add a script that hides the image when the button is clicked + > Stage, commit, and push changes. Let Git be on your team. #### Part Two -1. Create an HTML file called `about.html` +1. - Create an HTML file called `about.html` - - Must have global HTML document structure + - Must have global HTML document structure 2. Stage, commit, and push changes. Let Git be on your team. 3. Create a simple "About Me" webpage and using JS and the DOM to manipulate elements. -4. Title your webpage *About Me* and add this code +4. Title your webpage _About Me_ and add this code + ```html

    ``` @@ -84,55 +75,52 @@ 9. Complete the following tasks below using the DOM methods: - - Change the body style so it has a `font-family` of `Arial, sans-serif`. + - Change the body style so it has a `font-family` of `Arial, sans-serif`. - - Replace each of the values with your own information. + - Replace each of the values with your own information. - > Stage, commit, and push changes. Let Git be on your team. + > Stage, commit, and push changes. Let Git be on your team. - - Change the `
  • ` style to a color of your choosing. Cannot be black. + - Change the `
  • ` style to a color of your choosing. Cannot be black. - > Stage, commit, and push changes. Let Git be on your team. + > Stage, commit, and push changes. Let Git be on your team. - - Find a picture and add to the project. + - Find a picture and add to the project. - - Create a new `img` element and set its `src` attribute to a picture of you. Append the image to the web page. + - Create a new `img` element and set its `src` attribute to a picture of you. Append the image to the web page. - > Stage, commit, and push changes. Let Git be on your team. + > Stage, commit, and push changes. Let Git be on your team. #### Part Three -Using the great power of the DOM and its methods, iterate through the elements in the HTML document and create a Table of Contents that will be at the top of the webpage. +Using the great power of the DOM and its methods, iterate through the elements in the HTML document and create a Table of Contents that will be at the top of the webpage. 1. Create a new HTML file and add the code below. ```html -
    -

    Table of Contents

    -
    -
    -
    -

    Fruits

    -

    Red Fruits

    -

    Apple

    -

    Raspberry

    -

    Orange Fruits

    -

    Orange

    -

    Tangerine

    -

    Vegetables

    -

    Vegetables Which Are Actually Fruits

    -

    Tomato

    -

    Eggplant

    -
    +
    +

    Table of Contents

    +
    +
    +
    +

    Fruits

    +

    Red Fruits

    +

    Apple

    +

    Raspberry

    +

    Orange Fruits

    +

    Orange

    +

    Tangerine

    +

    Vegetables

    +

    Vegetables Which Are Actually Fruits

    +

    Tomato

    +

    Eggplant

    +
    ``` + 2. Stage, commit, and push changes. Let Git be on your team. -3. Add a script to the HTML document that iterates through the elements and creates a table of contents. The table of contents should be at the top of the webpage. +3. Add a script to the HTML document that iterates through the elements and creates a table of contents. The table of contents should be at the top of the webpage. 4. Stage, commit, and push changes. Let Git be on your team. - - - - diff --git a/js-dom.html b/js-dom.html new file mode 100644 index 0000000..6a88def --- /dev/null +++ b/js-dom.html @@ -0,0 +1,24 @@ + + + + + + + JS DOM Lab + + + + + +

    one

    +

    two

    + + + + + + + + + + diff --git a/myPhoto.jpg b/myPhoto.jpg new file mode 100644 index 0000000..1c6c887 Binary files /dev/null and b/myPhoto.jpg differ diff --git a/tabCont.html b/tabCont.html new file mode 100644 index 0000000..28ca850 --- /dev/null +++ b/tabCont.html @@ -0,0 +1,36 @@ + + + + + + + _Table of Contents_ + + + + +
    +

    Table of Contents

    +
    + +
    + +
    +

    Fruits

    +

    Red Fruits

    +

    Apple

    +

    Raspberry

    +

    Orange Fruits

    +

    Orange

    +

    Tangerine

    +

    Vegetables

    +

    Vegetables Which Are Actually Fruits

    +

    Tomato

    +

    Eggplant

    +
    + + + + + + \ No newline at end of file