Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Modure Rares
Courses Plus Student 9,041 PointsSticky navigation with javascript. Please help me guys.
I need to make a sticky navigation when scrolling but my code has no effect. Please help me I really need this done.
$(function(){
$(window).scroll(function(){
if($(document).scrollTop() > 300){
$('#navbar').addClass('sticky');
} else {
$('#navbar').removeClass('sticky');
}
})
});

Cengiz Demir
5,055 PointsYou need to .offset().top;

Raymon Oleaga
19,298 PointsThe firs code works form me. I would just make sure you are targeting the correct ID and or that the class that you are using does infract stick... so maybe you need to check your CSS.
When you scroll do you see when the class is added or not at all?
Modure Rares
Courses Plus Student 9,041 PointsModure Rares
Courses Plus Student 9,041 PointsI tried this too but it still doesnt work.