Initialize script

前端 未结 4 1790
灰色年华
灰色年华 2021-01-25 10:01

I need to learn how to initialize scripts. I have google it but dont dont really understand it.

Right now I have a toggle-script that is in a div, that entire div gets l

4条回答
  •  一整个雨季
    2021-01-25 10:30

    Are you calling it after the elements are loaded on the page?

    You should be using on() with jQuery 1.7+

    $(document).on("click", ".class", function () {
        $(this).toggleClass("add_class");
    });
    

    If you want to keep your syntax, you would have to do it either after the elements are rendered, or do it on document.ready.

提交回复
热议问题