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! While you're at it, check out some resources Treehouse students have shared here.
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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Modure Rares](https://secure.gravatar.com/avatar/c59d5c2b8ec8534b2046bb4d8a222f5f?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
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](https://secure.gravatar.com/avatar/320e0f4b07a43831975eb20b68ed899a?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Cengiz Demir
5,055 PointsYou need to .offset().top;
![Raymon Oleaga](https://uploads.teamtreehouse.com/production/profile-photos/1329492/micro_RayOleaga.jpg)
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.