Patryk Warda
Patryk Warda

Reputation: 23

Jscript element.style dont working in script.js (visual studio code)

(On start sorry for my english) I have one big problem in the last my project i dont have any problems, the problem appeared in the new project.

I have 3 files (index.html, script.js and style.css)

This is my index

<body>
<header>
    <div class="wrap"></div>
    <div class="logo">
        <p>Dzik_Company</p>
    </div>
    <p class="load">Loading</p>
    <div class="square"></div>
</header>

<script src="script.js">
</script>

And this is my script.js

const kwadrat = document.querySelector('.square');
const loading = document.querySelector(".load");
// setTimeout(hiddenElement, 3000);
function hiddenElement() {
kwadrat.style
}

And here (kwadrat.style) is problem, vscode not spoiler me (.style), in the last project vscode spoiler me .style.(value). Ss from project SS in last project (spoiler) Can you help me?

Upvotes: 2

Views: 1421

Answers (1)

Matt Bierner
Matt Bierner

Reputation: 65353

The style property only exists on html elements. However a query selector like '.square' may return any type of element. VS Code cannot know that it will return a div or even that it will return an html element.

You can use a jsdoc type annotation to let VS Code know what this querySelector returns an HTMLElement:

/** @type {HTMLElement} */
const kwadrat = document.querySelector('.square');

enter image description here

Upvotes: 4

Related Questions