QuakeLive Posted January 15, 2014 Share Posted January 15, 2014 Hi, I have a question about Creating Modal Windows example... Quote: function openModal() { 'use strict'; document.getElementById('closeModal').onclick = closeModal; document.getElementById('modal').style.display = 'inline-block'; document.getElementById('openModal').onclick = null;}function closeModal() { 'use strict'; document.getElementById('openModal').onclick = openModal; document.getElementById('modal').style.display = 'none'; document.getElementById('closeModal').onclick = null;}window.onload = function() { 'use strict'; document.getElementById('openModal').onclick = openModal;}; If I remove the following lines (altogether, all three lines): In function openModal(): document.getElementById('openModal').onclick = null; In function closeModal(): document.getElementById('openModal').onclick = openModal; In function closeModal(): document.getElementById('closeModal').onclick = null; so that the new code looks like this: function openModal() { 'use strict'; document.getElementById('closeModal').onclick = closeModal; document.getElementById('modal').style.display = 'inline-block';}function closeModal() { 'use strict'; document.getElementById('modal').style.display = 'none';}window.onload = function() { 'use strict'; document.getElementById('openModal').onclick = openModal;}; everything works well, there are no errors. I don't understand why there are these three lines? Thank you in advance! Link to comment Share on other sites More sharing options...
Larry Posted January 15, 2014 Share Posted January 15, 2014 The point of those lines is to drop event handlers when they're not needed. This is a tidiness issue, that's not required, and won't affect the functionality, but is arguably more professional and can prevent memory leaks. 1 Link to comment Share on other sites More sharing options...
QuakeLive Posted January 16, 2014 Author Share Posted January 16, 2014 Ok, thank you very much! Link to comment Share on other sites More sharing options...
Recommended Posts