I have the following index.html, there I have two sections of section 1 and section 2, as shown in the screenshot

Index.html
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <script type="text/javascript" src="/jquery.min.js"></script> <script type="text/javascript" src="myscript.js"></script> <script> jQuery(document).ready(function() { jQuery('.mySectionOne').updateCommonVar({commonVar:1}); jQuery('.mySectionTwo').updateCommonVar({commonVar:1}); }); </script> </head> <body> <p>Section 1:</p> <div class="mySectionOne"> <button class="add">add</button> <button class="sub">sub</button> <button class="show">show</button> <p>The value of Common var in section one is:<span class="showVal"></span><p> </div> <p>Section 2:</p> <div class="mySectionTwo"> <button class="add">add</button> <button class="sub">sub</button> <button class="show">show</button> <p>The value of Common var in section two is:<span class="showVal"></span><p> </div> </body>
In Index.html I use my own custom jQuery plugin "updateCommonVar", the definition for the plugin is present in myscript.js
myscript.js
(function( $ ) { $.fn.updateCommonVar = function (options) { var defaults= { commonVar:0, } var ParameterObject= $.extend({}, defaults, options); this.each(function() { $(this).find("button.add").bind("click", {commonVar:ParameterObject.commonVar},fnAddOne); $(this).find("button.sub").bind("click", {commonVar:ParameterObject.commonVar},fnSubOne); $(this).find("button.show").bind("click",{commonVar:ParameterObject.commonVar},fnShow); }); return this; }; function fnAddOne(e){ e.data.commonVar++; } function fnSubOne(e){ e.data.commonVar--; } function fnShow(e){ $(this).parent().find('.showVal').html(e.data.commonVar); } })( jQuery );
I pass the value of the commonVar variable as "1" from index.html for the section, I bind an event handler for each add sub button and show in the plugin definition, here I want
when you click the add button: the variable I passed commonVar to increase by 1. when you click the button: the variable I passed commonVar to be deccremented by 1. when you click the add button: the variable i passed to commonVar should be displayed in the span tag with the showVal class.
First I clicked the Add button, and then I clicked the Show button, but still I got the commonVar value as 1 not the expected value of 2 . I'm not sure about passing a shared variable between event handlers. Please help me with this. Thanks in advance for any help.
I expect the same behavior for section2, but still I got what I got for the note of section 1: section 2 is independent of section 1.
Wednesday for the same: http://jsfiddle.net/shmdhussain/PXYAh/1/