Welcome to Idea R | Branding - Web Agency - Digital Strategies
Switch to the mobile layout

      Idea R - Bring out your brand - Web Marketing strategies
  • HomeHome
  • About UsAbout Us
  • ContactsContacts

Blog

Take a software geek from the 80s, add a new generation graphic designer and dilute with a longtime marketing strategist. Shake vigorously and you'll get the Idea R's blog.

Change language... italiano
Go to the blog summaryGo to the blog summary

You may be interested in

Tracking Facebook likes with Google Analytics, the real solution!

Tracking Facebook likes with Google Analytics, the real solution!

How to monior Facebook interaction of your customers and analyze their impact on your conversions

How to dramatically increase social media LIKEs to your web site

Here's a free download that I created some time ago. It's a good tool for increasing engagement, but use with caution.

Last published

[Free eBook] 50+ tips for getting first on search engines and overtake the competition

[Free eBook] 50+ tips for getting first on search engines and overtake the competition

Do not miss this free ebook. Take advantage of a plurennial SEO experience and get tons of new visitors by improving your website optimization.
Metalworking industry: how to multiply customers using only the website and zero advertising budget

Metalworking industry: how to multiply customers using only the website and zero advertising budget

Find out how to design a website for the metalworking industry, that will be a magnet for customers and able to triple your leads.

Most popular

Lazy loading and the SEO problem, solved!

Lazy loading and the SEO problem, solved!

The best SEO solution to index your dynamically loaded contents, no more compromises!

Case study: TAV Engineering, branding for B2B services

How to create a brand that keeps distance from the cold and aseptic image of the metal industry, focusing instead on the human aspect.

Editor's pick

Mental marketing secret #1: the fake compromise

Mental marketing secret #1: the fake compromise

Can mentalism influence marketing? As a marketing professional and a long term magician, I will reveal you some tricks.
newsletter

Stay informed on digital strategies

jQuery: come lanciare e gestire gli eventi personalizzati

Published on 11/22/2012
Categories: Web Design
jQuery: come lanciare e gestire gli eventi personalizzati

This article is available in English too.

Avevamo già visto in un articolo precedente come gestire gli eventi JavaScript.
jQuery semplifica ma soprattutto uniforma il motore di eventi di JavaScript con 2 semplici metodi: bind() per sottoscriversi ad un evento e trigger() per lanciarlo.

Gli eventi non sono però solo una prerogativa degli oggetti standard DOM (Document Object Model), anche i vostri oggetti possono lanciare eventi, persino se non hanno nulla a che fare con il DOM.
In linea generale con jQuery ci si sottoscrive agli eventi usando le seguente forma

$(mySelector).bind('click', function(event){...});

o la forma più contratta

$(mySelector).click(function(event){...});

Come anticipato ci si può sottoscrivere anche ad eventi personalizzati, con

$(mySelector).bind('mycustomevent', function(event){...});

che a loro volta verranno lanciati dall'oggetto personalizzato con

$(mySelector).trigger('mycustomevent');

Domanda: se volessi passare delle informazioni all'event handler al momento del binding?
Risposta: si può passare qualsiasi informazione specificandola nell'istruzione bind che poi l'event handler recupererà dalla proprietà data dell'oggetto event.

// Use myCustomData to hold bind-time data
$(mySelector).bind('mycustomevent', myCustomData, function(event)
{
    ...

    // event.data contains myCustomData
    var myData = event.data;

    ...
});

Altra domanda: e se volessi passare delle informazioni all'event handler al momento del lancio dell'evento?
Risposta: si definisce semplicemente un parametro aggiuntivo nell'event handler.

// Use myParam to hold trigger-time data
$(mySelector).bind('mycustomevent', function(event, myParam){...});
...
$(mySelector).trigger('mycustomevent', 'this is the trigger-time parameter');

See also

Eventi JavaScript? Che confusione!

Vediamo di fare un po' di ordine sul sistema di eventi JavaScript e di capire quale usare a seconda della situazione.

You are the reader number 6,884.

Comments

Creative Commons License

Photographies, videos, graphics and texts by Idea R are licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

Previous article

Previous article

An App to see Amsterdam through Anne Frank's eyes

Next article

3 methods to detect mobile devices in ASP.NET

Next article
  • Visual Communication, Art DirectionVisual Communication, Art Direction
  • Apps, Cloud, Mobile, Software DesignApps, Cloud, Mobile, Software Design
  • Digital StrategiesDigital Strategies
  • BlogBlog

Scroll to top