I need to handle a dynamic button that will remove all the Tagify tags. The documentation for deleting all tags with jQuery is here: https://yaireo.github.io/tagify/#section-jquery
In the documentation it says:
// get the Tagify instance assigned for this jQuery input object so its methods could be accessed
var jqTagify = $input.data('tagify');
// bind the "click" event on the "remove all tags" button
$('.tags-jquery--removeAllBtn').on('click', jqTagify.removeAllTags.bind(jqTagify))
With this in mind, I have tried without success the following (can be seen here in JSFiddle):
$(document).on('click', '#btn-test', function()
{
var $input = $('#input-test').tagify();
$input.removeAllTags();
});
I also tried to create an approach closer to what the documentation states:
$(document).on('click', '#btn-test', function()
{
var $input = $('#input-test');
var _tagify = $input.data('tagify');
_tagify.removeAllTags();
});
But in both situations the error is:
Cannot read property 'removeAllTags' of undefined
I can't bind directly the remove function to a DOM element because buttons will be created on-the-fly.