Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
understandingDOM/js/main.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
43 lines (35 sloc)
1.32 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 1) | |
Write a function that calcuates and RETURNS the product of two | |
numbers. I should be able to use the function like the code below: | |
*/ | |
function getProduct(num1, num2) { | |
result = num1 * num2 | |
return result | |
} | |
var prod = getProduct(5,8); | |
console.log(prod+5); | |
/* 2) | |
Write a Javascript function that takes TWO parameters: element and class. | |
The element should be a DOM object, NOT a string. The class can be a string. | |
The function should add the designated class to the element. The code below should work */ | |
function addClassToElement(ele, cl) { | |
ele.className += " " + cl; | |
} | |
// function fancyLog(text, element) { | |
// console.log(text); | |
// // Now what goes in here? | |
// var element = document.createElement(element); | |
// element.innerHTML = text; | |
// document.querySelector("#log").appendChild(element); | |
// } | |
var p = document.getElementById("item"); | |
addClassToElement(p, "class1"); | |
/* 3) | |
A function that creates any type of element given, adds content to it, and adds it to the page in an intended parent. The code below should work. The PARENT should be a DOM object, not a selector. */ | |
function addItemToParent(ele, text, parent) { | |
var ele = document.createElement(ele); | |
ele.innerHTML = text; | |
parent.appendChild(ele); | |
} | |
var parent = document.getElementById("container"); | |
addItemToParent("h1", "This is some content",parent); |