Questions
Using JavaScript how would you solve these problems?
REMEMBER: You can do anything with code, you just need to think of what you need to do, google it, and implement that code into your solution
-
How do you get an element's ID
document.getElementById('id').id
-
How do you create a h1 tag
document.createElement('h1')
-
How do you add a class to an element
This is if there's already a class.... Add an ID to your element to make it easier to select. document.getElementById("div1").className += " otherclass";
-
How do you add some text inside of an element
element.innerHTML = "text"
-
How do you create a paragraph tag
document.createElement('p')
-
How do you remove the child of an element
document.removeChild(element)
-
How do you get the value entered in an "input" area
Give the text input an ID (<text area>) then document.getElementById("id").value;
-
How do you set an elements attribute
element.setAttribute(attribute, value)
-
How do you change the style of an element to display:none
element.style.display = "none"
-
How would you change a value for a:hover
a:hover.style.value = "value"