JavaScript jQuery Basics Introducing jQuery jQuery vs. JavaScript

I was following the teacher's activity in my workspace and none of them worked for me like in the video.Version?

1. const box = document.querySelector(".box"); box.style.display = "none";

The box disappeared in about a second later

2. $('.box).hide();

The box remained there. No change on the site.

3 Answers

darryn
darryn
17,347 Points

Hi Zoltan,

For #1 I don't think JavaScript can hide anything until the entire page loads. That's why you see the box flash before it disappears.

For #2 it just looks like you didn't close the single quotes around the box class. A simple typo that we all make.

Steven Parker
Steven Parker
201,319 Points

Good eye! No wonder your avatar is an eagle! :wink:

Thanks a lot! That was the problem...

Steven Parker
Steven Parker
201,319 Points

When you say "about a second later", do you mean a second after you refreshed your browser?

The workspace provide a way to create code for your browser, but changes made there will not be visible on their own. You can only see the results of code changes by first saving the file and then refreshing your browser.

Yes, Steve. After saving the app.js and refreshing the browser or hitting the preview button the box is there. And then a miracle happens and disappears.

Steven Parker
Steven Parker
201,319 Points

We might be able to uncover the mystery if you make a snapshot of your workspace and post the link to it here.

darryn
darryn
17,347 Points

Yeah. Thanks, Steven! Looking forward to when you hit 100k :0)

Steven Parker
Steven Parker
201,319 Points

Well, I seem to have done it. :wink: But now I've discovered a new bug:

six digit bug