Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My understanding of your problem is that you're trying to toggle between maps and when you toggle, click event handlers are attached to the maps links.</p> <p>First for toggling, you'll want to keep track of which one is visible so that you can properly hide it and make the other visible:</p> <pre><code>var unique_link = $$('#my_unique_id a'), // keep track of which map is visible currentMap = map1; unique_link.addEvent('click', function(e){ // Prevent the default behavior, but still allow bubbling of events e.preventDefault(); // Hide the current map currentMap.setStyle('display', 'none'); // store the correct map by comparing the two maps and making it visible currentMap = (currentMap == map1 ? map2 : map1).setStyle('display', 'block'); }); </code></pre> <p>To clarify, <code>currentMap = (currentMap == map1 ? map2 : map1)</code> is called a ternary operation. It's shorthand for if/else, which could be rewritten as:</p> <pre><code>if (currentMap == map1) { currentMap = map2; } else { currentMap = map1; } currentMap.setStyle('display', 'block'); </code></pre> <p>Next, why do you need to remove the events on the links in each map? Couldn't they stay attached when you toggle between maps?</p> <p>Lastly, you asked about event delegation and accessing values on click. Here is an example how how it works in MooTools:</p> <pre><code>// We pass an array of map1 and map2 through $$ to make sure that the returned value is an element collection // So we can use addEvent on both elements. // The event "type" we would have passed to addEvent has changed, using a psuedo event called "relay", which handles event delegation // It takes a selector for matching elements // The function that is passed to addEvent has two arugments, e, which is the event object, and element, which is the element that the // event is being delegated to. $$([map1, map2]).addEvent('click:relay(a)', function(e, element){ // Prevent the default behavior of the anchors e.preventDefault(); // element argument is the anchor. So you can access it this way. element.get('href'); // or "this" can also be used. this.get('href'); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload