What effect do eventlisteres have? I am talking about large numbers, here is an example:
- Only x quantity
.marker first - All children are added via
JS when clicking .marker - eventlistener - Each child has its own thing, which means that each of them has their own performers of events.
<div class="marker"> <div class="remove"></div> <div class="change"></div> <div class="add"></div> <div class="drag"></div> </div>
var count = 20 000; for(i = 0; i < count; i++) { var marker = document.createElement('div'); marker.className = 'marker'; someParentElement.appendChild(marker); marker.click( function() { //Create child elements var remove = document.createElement('div'); remove.className = 'remove'; marker.appendChild(remove); var change = document.createElement('div'); change.className = 'change'; marker.appendChild(change); var add = document.createElement('div'); add.className = 'add'; marker.appendChild(add); var drag = document.createElement('div'); drag.className = 'drag'; marker.appendChild(drag); //Children eventlisteners remove.click( function() { //Do it thing }); change.click( function() { //Do it thing }); add.click( function() { //Do it thing }); drag.click( function() { //Do it thing }); }); }
Please ignore other things, for example, creating 20,000 items programmatically. My question is this: what would it be like to have all these eventlisteners with all this code in them? It doesn't matter what or what code is inside the eventlistener, if it wasn’t running
source share