$(window).scroll(function() { if ($(this).scrollTop() > 1){ $('header').addClass("sticky"); } else{ $('header').removeClass("sticky"); } }); 

$ ('header') apply to html or css tag class?

    2 answers 2

    I do not see the context but in this case to the html tag.

    • How to make an attachment. For example, a inside header or div header as <header> <a href=""> <img src = "../ images / ico2.png"> </a> ... ???? - TomasRedl
    • Make an investment of what and where? Using javascript ? - Alexander Ischenko
    • Using javascript. If for example you need to make it so that the a tag inside the div tag changes the class when scrolling - TomasRedl
    • So what is the code that you specified does not suit you? - Alexander Ischenko
    • $(window).scroll(function() { if ($(this).scrollTop() > 100){ //Если окно прокручено больше чем на 100 писелей $('some_div').addClass(".some_class");// Добовляем .some_class } else{ $('some_div').removeClass(".some_class"); // Иначе убираем } }); - Alexander Ischenko

    Thank you very much! I found the solution myself through document.getElementById