+ 1
Why this simple js code doesn't work properly as expected
<!Doctype html> <html> <head> </head> <body> <p>nothing</p> <script> var x = document.getElementsByTagName("p"); x.innerHTML = "everything"; </script> </body> </html> //The output is: nothing :/
1 Answer
+ 5
getElementsByTagName returns an array, you can't access innerHTML of an array.
Use getElementsByTagName('p')[0]