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.
Actually you don't need ID for widget removing. Please check my script.
var gridster = $('.gridster ul').gridster().data('gridster');
$(document).on( "click", ".gridster ul li", function() {
$(this).addClass("activ");
gridster.remove_widget($('.activ'));
});
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