Search code examples
javascriptdocumentadobe-brackets

Why can't I use document in Brackets?


I'm using the Brackets IDE and I tried basic JS. Using the object document sends me to an error saying

"ERROR: 'document' is not defined. [no-undef]",

I can't find out why is this error happening since it works perfectly in dreamweaver, does anyone know why is this happening in Brackets? Thank you.

HTML:

<!DOCTYPE HTML>
<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <title>Parrafos</title>
    </head>

    <body>
        <p>a</p>
        <p>aa</p>
        <p id="special">especial</p>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
        <script type="javascript" src="parrafos.js"></script>
    </body>
</html>

JS:

function parrafo(texto, id) {
    document.getElementById(id).textContent = texto;
}

parrafo("Hola qué tal", "especial");

Solution

  • document is not part of JavaScript, it is part of the browser DOM.

    Whatever linter (e.g. JSHint, JSLint, ESLint) you have configured Brackets to use to test you code with hasn't been configured to assume the presense of global variables that exist when you run the code through a script element in an HTML document.

    Consult the documentation for whichever linter you are using to find out how to do that (likely this will either be a configuration file in the root of your project directory or a specially formatted comment at the top of your JS file).