Is there any way to check if an element has jquery select2 already applied to it?

后端 未结 4 2036
遇见更好的自我
遇见更好的自我 2021-01-03 18:03

I want to apply select2 to a bunch of jquery elements on the page that all have the same class name but it looks like if i call select2() on an element that already has had

4条回答
  •  隐瞒了意图╮
    2021-01-03 18:10

    Working solution:

    $('.MyDripdowns:not([class^="select2"])').each(function (i, obj) {
        $(obj).select2({width: "455px"});
    })
    

    Links:

    1. ^= attribute starts with selector
    2. :not selector

提交回复
热议问题