“JavaScript Delegasi Acara” Kode Jawaban

JavaScript Delegasi Acara

Explain event delegation :

“Js event listeners fire not only on a  single DOM element 
but on all its descendents”

The idea is that if we have a lot of elements handled in a 
similar way, then instead of assigning a handler to each of 
them – we put a single handler on their common ancestor.

Glorious Gull

Contoh delegasi acara dalam javascript

	selector = ".buttonClass";
document.getElementById('buttons').addEventListener('click', event => { // Step 2
      if (event.target.matches(selector)) {
        console.log('Click!');
      }
    })
Javasper

Jawaban yang mirip dengan “JavaScript Delegasi Acara”

Pertanyaan yang mirip dengan “JavaScript Delegasi Acara”

Lebih banyak jawaban terkait untuk “JavaScript Delegasi Acara” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya