Add jQuery colorbox plugin to a dynamically created element

前端 未结 6 1389
别跟我提以往
别跟我提以往 2020-12-15 07:36

The usual way to assign color box functionality on a link is like this:

$(\"a.colorbox\").colorbox({ transition: \"elastic\" });

Newly added

6条回答
  •  無奈伤痛
    2020-12-15 08:15

    As live is depreciated, you should use on

    $('body').on('click', '.colorbox', function() {
        $('.colorbox').colorbox({rel: $(this).attr('rel')});
    });
    

    This code also allows grouping.

提交回复
热议问题