Reference Guide
facebook FBML Reference Guide Page 152 of 159
firedByDescription.setTextValue('');
return true;
}
//otherwise... do some processing:
//*VERY IMPORTANT*: note that the object, which fired the event is located two nodes up in the DOM tree
//See note below
//eventFiredBy_ObjectId = evt.target.getParentNode().getParentNode().getId();
//On newer versions, it seems that there is no need to go up two levels int he DOM tree, hence
eventFiredBy_ObjectId = evt.target.getId();
//works, whereas the first does not!
//**NOTE** My testing of this suggests that when you call addEventListener() it adds it to the element, AND
all it's descendants
// This can then cause the event to be fired multiple times, as it is fired for the element and it's descendant
elements.
// When fired by a descendant element, you will probably have to do some kind of getParent()-ing
// I'm raising this as a bug, as it does make things a little unworkable!
//once you have the ID, you may, for example, drop its id into the firedByDescription div:
firedByDescription.setTextValue(eventFiredBy_ObjectId);
//... or do some conditional processing:
if (eventFiredBy_ObjectId == 'foo') {
//do something if the event was fired by 'foo'
} else {
//do something if the event was fired by 'bar'
}
}
//add event listener to 'foo' div (mouseover & mouseout)
document.getElementById('foo').addEventListener('mouseover',myEventHandler);
document.getElementById('foo').addEventListener('mouseout',myEventHandler);
//add *the same* event listener to 'bar' div (mouseover & mouseout)
document.getElementById('bar').addEventListener('mouseover',myEventHandler);
document.getElementById('bar').addEventListener('mouseout',myEventHandler);
</script>
This functionality is very useful in cases where you have one event handler for multiple objects of the same
type. Take for instance a shopping cart of some sort, or any type of object browser. When a user moves her
mouse over one of the items in the cart, you may want to conditionally display information about the item -- by
finding its ID, you may associate a description text for that item and display it to the user in another div. As you
can see, using event listeners can be a very powerful way to display useful additional information to the user,
based on where they move their mouse within your Facebook application. Happy coding and creativity!
www.yapish.com










