4a.13. Back to event handlersYou're almost ready to write the code for addToTop5()... but there's one more detail you need to think about. Once you've moved the CD cover image down into the "top5" <div>, you've got to remove the event handler that runs addToTop5() when the cover is clicked on. addToTop5() will move the CD cover image from the top "cds" <div> to the lower "top5" <div>. Once the CD is in the Top 5 listings... ...we don't want addToTop5() to run when the cover is clicked on. addToTop5()addToTop5() should only run when a CD in the "cds" <div> is clicked... but not when a CD already in the "top5" <div> is clicked. 4a.13.1. Remember how we added the event handler?function addOnClickHandlers() { var cdsDiv = document.getElementById("cds"); var cdImages = cdsDiv.getElementsByTagName("img"); for (var i=0; i<cdImages.length; i++) { cdImages[i]This is the <img> element for the CD cover....onclick...and this is the event handler name. = addToTop5;Here's the event handler to run. You can remove this event handler by setting the handler property to null. } }
|