codedamn

Javascript error message in dom chapter

Asked by Rajnish Yadav about 2 months ago

0
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="style.css"> </head> <body> <h1>Hello world</h1> <script src="index.js"></script> </body> </html>

javascript code let heading=document.querySelector("h1") console.log(heading);

getting error message in terminal ReferenceError: document is not defined

1 Answer

    0

    The code seems working fine. If you are just running the JavaScript file then it will definitely raise an error saying document is not defined. Try creating a HTML/CSS Playground, paste your code in html and js files respectively and than you should be able to see the h1 node in console.

    @umangajw

    Umang Ajwalia

    @umangajw

Your answer