How to remove a single widget from gridster.js by his dynamically created id

Viewed 9643

I need to know how can I remove a single gridster.js widget by his dynamically created id with gridster.add_widget. Every new widget created has an own button to remove that single widget, but I can't make it work.

Here is my Code

$(document).ready(function(){

var count = 0;
var newid = count + 1;

    $(document).on("click", "#newGrid", function() {
        var gridster = $(".gridster ul").gridster().data('gridster');
        gridster.add_widget('<li id="block"'+newid'>Hello, now delete me <span id="remove"'+newid'>x</span></li>',2 ,1);
    });

    $(document).on('click', '#remove'+newid, function() {
    var gridster = $(".gridster ul").gridster().data('gridster');
        gridster.remove_widget( '#block'+newid );
    });

});

For adding widgets it works fine, but I can't remove widgets.

5 Answers
Related