Reputation: 2833
I was watching this video tutorial and I noticed he said that he's added this:
$('html').addClass('js');
He said that if javascript is disabled, then the class won't show, but if it is enabled, the class will show. I don't understand how that works. How does jQuery know if JS is enabled, and to apply a certain class when JS is enabled/disabled? There's no if statement. I'm a tad bit confused.
"If HTML has a class of JS, javascript is available, if not, JS is not available". I don't understand that.
He also mentioned a "JavaScript hook"..?
Watch from 2:30 to 3:40, it's where he explains it but I don't understand.
Thanks!
edit: I cannot believe the answer was so simple and I did not see it. Thanks guys.
Upvotes: 0
Views: 3030
Reputation: 2121
Here u can see that the line
$('html').addClass('js');
is inside <script> </script>
.
This gets executed only if the javascript is switched else this wont hence the class wont be added and the user views the normal content which is designed for the users without javascript.
And Btw I have followed all Jeffrey Ways tuts. They are just cool.
Upvotes: 1
Reputation: 13461
If javascript is enabled and jquery is loaded then
$('html').addClass('js');
this code block will run and it will add a js
class to html element.
And if javascript is disabled jQuery won't run, as jQuery is a javascript library and no class will be added.
Upvotes: 0
Reputation: 11931
If the JavaSCript is not enabled, no JavaScript will run, so no jQuery either. The line $('html').addClass('js');
only shows when there is JavaScript, because then that line will run and add the class to the HTML tag.
Upvotes: 0
Reputation: 1227
jQuery is written in JavaScript and won't be executed when JS is disabled.
Upvotes: 1
Reputation: 3579
jQuery is a javascript library, so if javascript is not enabled, the jQuery code won't be executed and the class will not be added.
Upvotes: 1
Reputation: 26380
jQuery is JavaScript. It's a library of useful code, written in JavaScript. If JavaScript is disabled, so is jQuery, so you won't see the "js" class appear. It's not the sort of test you'd do on a working site; it's more of a demonstration for learning purposes.
Upvotes: 4