I'm trying to read a collection from the html5 data-attribute of the input that is converted to select2 to create tags.
This is working when I have one input:
$(".tags").select2(
width: '220px'
tags: $(".tags").data('collection')
)
But I will like to do it more safe using the data of the element itself, I tried this:
$(".tags").select2(
width: '220px'
tags: $(this).data('collection')
)
But it fails with the error:
Uncaught query function not defined for Select2 investigador_aplicaciones
Do you know if it is posible to use the element itself with a specific selector like $(this)?
You can do this instead:
$(".tags").each(function(){
var $this = $(this);
$this.select2({
width: '220px',
tags: $this.data('collection')
});
});
Because during your call this doesn't represent the element in the selector.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With