Pass dynamic id value jquery div jump to function

前端 未结 4 1151
忘了有多久
忘了有多久 2021-01-16 14:31

I am stuck at jquery div jump to problem. The problem is that i am creating dynamic and dynamic div also say <

4条回答
  •  迷失自我
    2021-01-16 14:32

    String Concatenation:

    $("#" + this.id + "_div").offset().top
    

    Note that there is no need to create unique IDs, DOM duo to having tree-like structure provides many different methods for traversing and selecting the target elements.

    Since you are generating the elements dynamically you should also delegate the events, you can add classes to your elements and use the on method:

    $('#aStaticParentElement').on('click', '.anchors', function() {
       // TODO:
       // select the target element either by traversing 
       // or by using an identifier
    });
    

提交回复
热议问题