0

Using Gridster, I can bind events on start and stop dragging. But how can I bind event to a single click on an item? I need to be able to select an item in order to remove it, or to set some properties to it.

3 Answers 3

0

You can use jquery click events to bind single click on an element. Here is an example of the same. Following is the general layout of the binding.

       $('.layout_block').click(function () {
                //function to set some properties using $(this)
                //setting an identifier to remove the element
       }

Here layout_block is the class to all the elements of gridster.

3
  • That will not work on elements added after initialization. I tried using $('.layout_block').on('click', function() {});, but that didn't work either. Jan 25, 2013 at 10:04
  • Any which method you use, the new elements will have to be register their eventhandler, which involves re-initializing the .click() function.
    – Nupur
    Jan 25, 2013 at 11:11
  • 1
    Ahh, of course! Now it works: var widget = gridster.add_widget('<li>foo</li>', size_x, size_y); widget.click(myFunction);. Thank you. Jan 25, 2013 at 11:47
0

javascript $(document).on("click", ".layout_block", handler);

worked for me, even for widgets that are added with gridster.add_widget();.

0

I have this working code.

$(".gridster ul li button.close").click(function () {
        gridster.remove_widget($(this).parent());
});

So Inside my Li element, I have a button with class=close on detecting the click event, I call the widget method gridster.remove_widget and pass the html element for it to remove.

Happy Coding :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.