21st Dec 2020, 1:36 AM
Boyan Ivanov
Boyan Ivanov - avatar
6 Antworten
+ 5
bop cho In html, we can have same class name in every element. So you have to get elements using getElementsByClassName. Though it returns an array so I have taken first element. function hello() { var name = document.getElementsByClassName('text')[0]; alert('hello,' + name.value); }
21st Dec 2020, 2:43 AM
A͢J
A͢J - avatar
+ 4
bop cho It's a small q querySelector
22nd Dec 2020, 2:47 AM
A͢J
A͢J - avatar
+ 2
running the code you get ‚document.getElementByClass is not a function....‘ This is because, well, getElementByClass is not a function. One way would be to instead use document.querySelector(".text"). Note the dot to tell that text is a class
21st Dec 2020, 1:49 AM
John Doe
+ 1
I Am Groot ! getElementsByClassName does not return an array. it returns an HTMLCollection
21st Dec 2020, 4:45 PM
John Doe
+ 1
I love u Groot, man!
22nd Dec 2020, 2:51 AM
Boyan Ivanov
Boyan Ivanov - avatar
0
I Am Groot ! John Doe ok, guys now pls look at it now and tell me what's wrong
22nd Dec 2020, 2:14 AM
Boyan Ivanov
Boyan Ivanov - avatar