javascript - jQuery click event fires twice -


I have a problem with content overlay scripts that I am developing. It seems that my expiration event takes place twice, but for the first time (or second time, depending on which link you click, depending on the link) returns 'undefined' returns.

You can find an example of a tampering work on JSFiddle:

If you click on 1, click on and then Click on 2 it undefined first, then dummy .

When I delete an opening link, then everything works fine

What causes the problem and how can I avoid it?

Edit: The code from JSFiddle is as follows: <(plugin, encryption,) (this ($, window, document, undefined) {"use strict" var Plugin = 'content overlay', defaults = {property: 'value'}; element = $ (element); this.options = $ .extend ({}, defaults, options); this.init ( );} Plugin.prototype = {/ ** * init * / init: Function () {var self = this; // Method of opening bind This $ Element.click (function () {self.open ();} ); // Close method $ ('# close'). (Function () {}.}}, / ** * open * / open: function () {this.overlay = 'dummy';}, / ** * Stop it * / Closed: Function () {Warning (this.overlay); // & lt; ==== Problem: Fire gets twice. Returns 'Undefined';} $ .fn [PluginName] = function (option } {Return.Each (function () {if (! $. Data (this, 'plugin_' + pluginName)) {$. Data (this, 'plugin_' + plugin name, new plugin (this, option));} Content Overlay ();})}} (JQuery, Window, Document);

A

  $ ('#closed'). Click (function () {self.close ();});   

You are binding both the objects close () the methods of the handler are actually, when you click the close button, it does two functions , One for each overlay object because one overlay object is missing, it is returning undefined .

You can reach this problem here:

  close: function () {If (this.overlay! = Undefined) {// Undefined Overlay Warning Leave on (this .overlay); }}   

Demo:

Comments