javascript - plugin save var inside each returned click -
you guys mind checking out jsfiddle made understand issue. http://jsfiddle.net/kr1zmo/dqbex/8/:
<a href="#" class="cref">item</a> <a href="#" class="cref">item 2</a> <a href="#" class="cref">item 3</a> <a href="#" class="cref">item 4</a> <p id="result"></p> <script language="javascript" type="text/javascript"> (function($) { $.fn.livebindtest = function() { return this['live']('click', function() { var savedvar; if (!savedvar || savedvar == 0) { // false, false things. savedvar = 1; jquery('#result').append(savedvar); } else { // true, true things. jquery('#result').append(savedvar); savedvar = 0; } return false; }); }; })(jquery); jquery(document).ready(function() { $('a.cref').livebindtest(); }); </script>
i want save variable each click.
take @ this example.
did want toggle bit of code execute? if want hold value in closure, you'll need declare outside of live event handler function.
if value needs held each element matched selector, use $(elem).data()
store value in example.
Comments
Post a Comment