0

Let´s say I have some DOM elements , then I have some events associated with those elements, event1->div1, event2->div1, event3->div2, event4->div2.

Now what I want is create an structure where I can have a map where elements are the key, and values are the arrays of events so at some point I can iterate the map and get key, and set the events that were unbind before.

I check jQuery map http://api.jquery.com/jquery.map/ but does not look like a map.

Any idea how to create that structure on Javascript?.

I try with the solution that mark my question as duplicated, but then when I iterate the map with foreach my key it´s just a string "[object Object]" instead of the element that I set. what I´m missing here guys.

        var elementEvents = [];
        var currentElement = $(this);//(div)
        loadClickElementEvents(currentElement, elementEvents);
        elementEventsMap[currentElement] = elementEvents;

When I iterate

        $.each(elementEventsMap, function (currentElement, elementEvents) {
        //currentElement it´s not the div element but String "[object Object]"
        /*jslint plusplus: true */
        for (i = elementEvents.length; i > 0; i--) {
            debugger;
            event = elementEvents.pop();
            console.log("binding event index " + i + " for  type " + event.type);
            currentElement.bind(event.type, event);
        }
    }); 

Regards.

paul
  • 12,873
  • 23
  • 91
  • 153

0 Answers0