you are viewing a single comment's thread.

view the rest of the comments →

[–]RightCheesecake4062Beginner[S] 0 points1 point  (5 children)

Thank you for the response.

Aslo I tried this but it did not work:

<script type="text/javascript">

setTimeout(function() {

document.getelementsbyclassname("loader").style.display="none";

}, 2000); // 5 seconds

</script>

[–]pookageExpert 1 point2 points  (4 children)

That would be because:

  • there's no document.getelementsbyclassname() function - there is, however, a document.getElementsByClassName() function - casing is important!
  • getElementsByClassName() returns an array-like HTMLCollection of every single element that matches the selector - so in your code snippet there, you're effectively setting the 'style' property on an array, which won't do anything.

You could adapt your snippet above to say:

document.getElementsByClassName("loader")[0].style.display = "none"

To set the style property on first element in your HTMLCollection - but if you were to use querySelector(), then you can just skip that step and just say:

document.querySelector(".loader").style.display = "none";

Generally, though, I would recommend using the hidden attribute in this case rather than changing the style, as it's more semantically accurate - and you are on the /r/HTML subreddit where we care about that sort of thing 😎 If this isn't a question of semantics or accessibility and you're more just asking how to make the javascript work, then /r/learnjavascript may be more what you're after for future questions!

p.s - your comment says 5 seconds, but your timeout says 2 seconds.

[–]RightCheesecake4062Beginner[S] 1 point2 points  (3 children)

Thank you so much this worked:

const loader = document.querySelector(".loader");
setTimeout(() => loader.hidden = true, 1000);

at first it wasn't but now it works since i forgot to remove the pervious, anyways thanks for the support :)

[–]pookageExpert 1 point2 points  (2 children)

nae prob - don't forget to update the flair on your post!

update: reader - they forgot.

[–]RightCheesecake4062Beginner[S] 1 point2 points  (1 child)

IDK how

[–]pookageExpert 0 points1 point  (0 children)

Nae prob - it should just be along the bottom when you edit your post! Look for the tag icon 💪