La delegazione di eventi è una tecnica Javascript/DOM che ho trovato utile in alcune occasioni, si tratta di non controllare ogni singolo nodo di cui ci interessa un evento, e monitorarne un altro nodo più in alto nella radice DOM.
Un esempio per chiarire: abbiamo una serie di campi input testuali, vogliamo controllare il cambiamento di tutti quanti; classicamente dovremmo attaccare un EventListener ad ognuno di essi (oppure aggiungere una proprietà onChange o simile). Beh invece si può attaccare un solo EventListener ad un elemento che contiene tutti i campi (come l’elemento “form” ad esempio).
Questo è possibile perché gli eventi si trasmettono attraverso l’albero dei nodi, per maggiori informazioni a proposito (ma diventa piuttosto tecnico), si trovano sulla documentazione ufficiale DOM, sezione Eventi.
Potrebbe però diventare utile, a questo punto, scoprire qual’è l’elemento che ha generato l’evento, perché this farà riferimento al nodo a cui abbiamo aggiunto l’EventListener, non al campo testuale. Tra le proprietà dell’evento infatti c’è target oppure srcElement, dipende dal browser. Per essere sicuro che funzioni, io utilizzo il seguente codice: var element = e.target || e.srcElement;
[via HTML]
Pingback: amazing feather hair extensions
Pingback: online casino uk
Pingback: Blackheads
Pingback: acnezine effective
Pingback: pink eye
Pingback: Camouflage wedding dresses
Pingback: image hosting
Pingback: what tool
Pingback: General Web Directory
Pingback: amor en linea
Pingback: Webhosting Nederland
Pingback: optometrist salary
Pingback: MBA online courses
Pingback: free money from the government for school
Pingback: Victoria secret promo codes
Pingback: Baby Bedding
Pingback: gps para camiones
Pingback: Take Away Containers
Pingback: ipad danmark
Pingback: where to buy acnezine
Pingback: Personalization Mall
Pingback: Fort Myers lawyers criminal
Pingback: grow taller 4 idiots
Pingback: Swiss T Gallery
Pingback: african mango weight loss pills
Pingback: african mango on dr oz
Pingback: african mango dr oz show
Pingback: control de flotas
Pingback: control de flotas
Pingback: used snowmobile
Pingback: facebook symbols
Pingback: project imagination
Pingback: Geberit
Pingback: bvlgari glasses
Pingback: short hair styles 2012
Pingback: black wedges for sale
Pingback: poetry
Pingback: Rolling Steel Buyer Guide
Pingback: motorhome rentals orlando
Pingback: Mandeville Attorneys
Pingback: LED v LCD
Pingback: consulta Tarot
Pingback: dia transportation
Pingback: Cheap Auto Insurnace in GA
Pingback: Chat Box
Pingback: kitchen remodeling Virginia
Pingback: LCD vs OLED TV
Pingback: wall mounted ladder
Pingback: control flota
Pingback: intuition
Pingback: rock dating
Pingback: how to get more lawn care customers
Pingback: wayfarer sonnenbrille
Pingback: best buy credit card
Pingback: how to make hair grow faster
Pingback: coq10 brands
Pingback: tampa criminal attorneys
Pingback: all season tires
Pingback: Buy Herbal Incense
Pingback: crazy weaponr deal
Pingback: i need to make money now
Pingback: lancaster car accident lawyer
Pingback: PPI Claim Scotland
Pingback: slots free
Pingback: cheap LCD HDTVs
Pingback: bamboo floor
Pingback: Card Processing
Pingback: cheap motels
Pingback: Design Award
Pingback: Panoramic
Pingback: my homepage
Pingback: temperature logger
Pingback: book rentals
Pingback: special valentines day gift ideas
Pingback: kindle vs nook
Pingback: Quotes Tebow
Pingback: word
Pingback: isuzu amigo
Pingback: best electronic cigarette
Pingback: gun app
Pingback: street soccer
Pingback: orange county answering service
Pingback: joinery auckland