0

I set an object as follows.

var buttons={};
buttons['Reset']=function(){
    ... do something
}
buttons['Refine']=function(){
    ... do something else
};

I then add buttons to a page as follows.

$.each(buttons, function(key, value) {
    var html='<div class="'+key+'">'+key+'</div>';
    $('.panel_buttons').append(html);
    $('.'+key).on('click',value).button();
});

I then dynamically add extra buttons to the panel_buttons element. For example, this may be a Save button when the user performs a drag and drop.

When a user performs drag and drop the same logic as shown above is used to add the extra button.

Later in my code I would like to refresh the object by interrogating the .panel_buttons element.

I am using Version 1.11.1 of jQuery.

How can I do this?

wurzel_gummidge
  • 287
  • 2
  • 11
  • what error you're getting implementing this? – Aminur Rashid Jan 07 '17 at 19:04
  • Hi @AminurRashid. I am not sure where to start to accomplish this. I am really after advice on firstly if it is possible to interrogate the panel_buttons element to retrieve the event handlers and labels of buttons inside it. Then, if it is, I would like to know what jquery method I can use to retrieve that data? Hopefully this would then lead to something which refreshes that object array. – wurzel_gummidge Jan 07 '17 at 19:23
  • it sounds possible, and `{}` notation is used for javascript object, not array. `[]` is the array notation. – Aminur Rashid Jan 07 '17 at 19:29
  • Thanks @AminurRashid. Re object and array, I have edited my question. – wurzel_gummidge Jan 07 '17 at 19:59
  • I am beginning to think that I am stumped on this one. If _data is the only method I can use, I understand that an underscore means it’s not advisable to use the method in production code. – wurzel_gummidge Jan 07 '17 at 21:00
  • didn't understand your last comment – Aminur Rashid Jan 08 '17 at 05:34
  • Hi @AminurRashid. Sorry I was referring to $._data(element, "events") which is referred to at [link](http://stackoverflow.com/questions/2518421/jquery-find-events-handlers-registered-with-an-object?rq=1). By the way this appears to work in jQuery 1.11.1 but is not recommended for production code. – wurzel_gummidge Jan 08 '17 at 18:10

0 Answers0