I'm initilizing select2.js
library on two select
element as follow:
$("#zones-list, #zones-list-popup").select2({
placeholder: "Select Your City",
dropdownParent: $(".modal-content"), // this line should only be for #zones-list-popup"
ajax: {
url: ...
As I've commented in the code above, I need to have this parameter dropdownParent: $(".modal-content")
only for #zones-list-popup
selector. Any idea how can I do a conditional thing inside a jquery function that has multiple selector?
CodePudding user response:
You can't, per se. Call select2
twice instead.
const options = {/*etc*/};
$("#zones-list").select2(options);
$("#zones-list-popup").select2({...options, dropdownParent: $(".modal-content")});