Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Konrad Pilch
2,435 PointsWhats wrong with this code?
jQuery(document).ready(function(){
var navOffset = jQuery("navbar-default").offset().top;
jQuery(window).scroll(function(){
var scrollPos = jQuery(window).scrollTop();
if (scrollPos >= navOffset) {
jQuery("navbar-default").addClass("fixed-menu");
}
});
});

Matthew Smart
12,567 PointsWhat is your actual problem? The class .fixed-menu isnt adding on?

Konrad Pilch
2,435 PointsYes, its not adding.

Matthew Smart
12,567 PointsThat could be for a number of reasons. What does it say in your console? Have you included jQuery into your project?

Konrad Pilch
2,435 PointsIt's all good.
it just says it just displays #document at the right end. But no errors.

Matthew Smart
12,567 PointsOKay, copy and past all of your html/css/javascript into a jsfiddle here https://jsfiddle.net/
And post the link so that i can replicate the issue

Konrad Pilch
2,435 PointsNot sur ehow to use that. Id pasted it here.
2 Answers

Carlos Federico Puebla Larregle
21,073 PointsMaybe I'm wrong but that "navbar-default" shouldn't be prefix with a dot or a "#" ?

Matthew Smart
12,567 PointsThe reason is that you are not selecting the element you wish to.
<div class="hello"></div>
To select this in jquery:
$('.hello')
If it was an ID like:
<div id='hello'></div>
Then you would select it like:
$('#hello')
So basically you have missed the . or # in your jquery selector.
Konrad Pilch
2,435 PointsKonrad Pilch
2,435 PointsOh right, I get confused because when we write addClass, we dont need to write anything because it knows it's a class : p
But it still doesnt work. I have no idea why.. and iv tried soo many things, knowing now fomr you guys that i wasn't selecting it -_-
Pleae help me with this code, but i mean with explanation :) I got the idea on how this ment to work, like if this pass 400px, then add class to navbar, if this is less than 400px, then remove the class, or with toggle i guess, im just not sure how to make this in jQuery. Im practicing.