-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (46 loc) · 1.31 KB
/
index.js
File metadata and controls
59 lines (46 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Show the alert function
alert('Hello world!');
// Show the window object
console.log(window);
// Show the document object
console.dir(document);
// Function that fires on button click
function btnClick(){
alert('The button has been clicked');
};
// .getElementById example
const headerOne = document.getElementById('headerOne');
console.dir(headerOne)
// inpout value example
const myInput = document.getElementById('myInput');
console.log(myInput.value)
// property examples
const myList = document.getElementById('myList');
// innerText
console.log(myList.innerText)
// innerHTML
console.log(myList.innerHTML)
// className
const divOne = document.getElementById('divOne');
console.log(divOne.className);
// classList
// Add A Class
myList.classList.add('show');
// Remove A Class
myList.classList.remove('show');
// Toggle A Class
myList.classList.toggle('show');
// .getElementByTagNames example
const list = document.getElementById('myList');
const numberOfLiTags = list.getElementsByTagName('li');
console.dir(numberOfLiTags);
// .getElemetByTagNames loop example
for (let i = 0; i < numberOfLiTags.length; i++){
console.dir(numberOfLiTags[i])
};
// change color of every other element
for (let i = 0; i < numberOfLiTags.length; i++){
if(i % 2 === 0){
numberOfLiTags[i].style.color = 'blue'
};
};