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

      Idea R - Do your competitors are always ahead? - Raise your voice with web marketing!
  • 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: how to throw and handle custom events

Published on 11/22/2012
Categories: Web Design
jQuery: how to throw and handle custom events

We've already seen in a previous article how to manage JavaScript events.
jQuery simplifies but most of all uniforms the JavaScript events engine with 2 simple methods: bind() for events subscription and trigger() to fire them.

Events are not only a prerogative of standard DOM (Document Object Model) objects, your custom objects can throw events too, event if they aren't DOM objects.
In general, with jQuery you subscribe to events using the following form

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

or the shorter

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

As mentioned above you can also subscribe to custom events, with

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

which in turn will be launched by the custom object using

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

Question: can I pass data to the event handler at the time of binding?
Answer: you can pass any information specifying it in the bind method and the event handler will retrieve it from the data property of the event object.

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

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

    ...
});

One more question: can I pass data to the event handler at trigger-time?
Answer: simply define an additional parameter in your 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

JavaScript events? What a mess!

Let's try to put some order on the JavaScript events paradigm and to understand which one to use and when.

You are the reader number 6,869.

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