2

I am writing a simple interactive widget that will eventually end up in an ibook.

It's a game where you drag and drop an item into the correct place, essentially matching animal sounds to the animals that make them.

I add my listeners in the HTML, like this for the target:

<div class="target_box_zebra"
     ondrop="drop(event,'zebra')"
     ondragexit="dragLeave(event,'zebra')"
     id="zebra_target"
     ondragenter="drag_enter(event,'zebra')"
     ondragover="allowDrop(event,'zebra_target')"
     ondragleave="drag_leave(event,'zebra')">
</div>

Once the correct target has been found (simple if statement) I want to remove all the listeners so that it is just an the plane div with its default background image.

I tried unbind but it didn't work. Any suggestions or guidance would be super.

1

1 Answer 1

1

Unbind only works, if you don't use inline handlers.

Check out https://developer.mozilla.org/en-US/docs/DOM/element.addEventListener.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. funnily enough this does seem to work, document.getElementById(thisTarget).ondragleave =false; document.getElementById(thisTarget).ondragexit =false; document.getElementById(thisTarget).ondragenter =false; document.getElementById(thisTarget).ondrop =false; document.getElementById(thisTarget).ondragover =false; which is messy but handy to know when mocking up something fast. I

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.