How to change plugin argument from one to two when clicking on the click button?

 one = { q: 1, w: 2, e: 3 } two = { q: 4, w: 5, e: 6 }; (function($) { var pl1, binded = false; $.fn.player = function(pl) { pl1 = pl; if (binded) return; $('#q').on('click', function() { alert(pl1.q) }); $('#w').on('click', function() { alert(pl1.w) }); $('#e').on('click', function() { alert(pl1.e) }); binded = true; }; })(jQuery); $(document).ready(function() { $().player(one); $('#r').on('click', function() { $().player(two); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <body> <button id="q">1</button> <button id="w">2</button> <button id="e">3</button> <button id="r">click</button> </body> 

http://jsfiddle.net/Tajaj/1/

    1 answer 1

     one = { q: 1, w: 2, e: 3 } two = { q: 4, w: 5, e: 6 }; (function($) { var pl1, binded = false; $.fn.player = function(pl) { pl1 = pl; if (binded) return; $('#q').on('click', function() { alert(pl1.q) }); $('#w').on('click', function() { alert(pl1.w) }); $('#e').on('click', function() { alert(pl1.e) }); binded = true; }; })(jQuery); $(document).ready(function() { $().player(one); $('#r').on('click', function() { $().player(two); }); }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <body> <button id="q">1</button> <button id="w">2</button> <button id="e">3</button> <button id="r">click</button> </body> 

    http://jsfiddle.net/Tajaj/2/

    • jsfiddle.net/CJQT7/1 Help with this example please. At the first call, the whole plugin works, and at the second binded = true and the code does not work - TANKIST