MooTools event listener disappears after element.innerHTML is changed?

Look at Element. Delegation to setup the event on the myDiv container one time, so you don't have to re-attach handlers each time the contents are updated. You need to include this MooTools-More extension in your scripts as it's not part of core yet, but will be starting from version 1.3.

You are attaching an event to an element that you are replacing. The dom has no way of knowing that to you, the old and the new button are identical. The old button is deleted (and the event listener with it) and the new button created.

So you need to re-attach the event to the new button.

When you set innerHTML on an element, the element's contents are completely cleared and replaced with a new set of elements -- the ones parsed from the innerHTML property. Any events set on the old elements will not apply to the new ones.

This is how JavaScript works, it's not a bug.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions