was trying to follow a utube vid, by freecode, https://www.youtube.com/watch?v=5fb2aPlgoys&t=418s. document.get… doesnt work in javascript vscode, the 2 tools they tell you to use.
We need to see your code. The DOM method getElementsByClassName works in all browsers.
Make sure you are using the camel case name and not the way it is typed in the code comment, it is getElementsByClassName
not GetElementsByClassName
const title = document.getElementById(‘main-heading’)
console.log(title)
c:\Users\joe\Desktop\tempCodeRunnerFile.javascript:1
const title = document.getElementById(‘main-heading’)
^
ReferenceError: document is not defined
ReferenceError: document is not defined
at Object. (c:\Users\joe\Desktop\tempCodeRunnerFile.javascript:1:15)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions…js (node:internal/modules/cjs/loader:1310:10)
Where is the corresponding html element with that id, in the index.html file?
<h1 id="main-heading">Favourite Movie Franchise</h1>
Post the entire code.
in the beginning it did work, all of a sudden i get this error. when i looked out on web, they all said, you cant do this
anyways, uninstalled node, vscode and now i get it to work.
It is a browser API, your code should run in the browser not using Node.js
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.