Jquery Toggle two function not work in jquery 1.10.1 but work's on Jquery 1.8.3
HTML
<p>For example, consider the HTML:</p>
<div id="target">
Click here
</div>
Jquery
$('#target').toggle(function() {
alert('First handler for .toggle() called.');
}, function() {
alert('Second handler for .toggle() called.');
});
and expmple is here
Dude it doesn't works in jQuery 1.10.1
Still there is another way to do it...
$(function () {
function first() {
//Code for first time click goes here
$(this).one("click", second);
}
function second() {
//Code for second time click goes here
$(this).one("click", first);
}
$("#target").one("click", first);
});
jQuery.toggle has been deprecated since version 1.8 and removed sometime later. You can write your own implementation instead:
function handler1() {
alert("first handler for .toggle() called.");
$(this).one("click", handler2);
}
function handler2() {
alert("second handler for .toggle() called.");
$(this).one("click", handler1);
}
$("#target").one("click", handler1);
Demo
DEMO
DEMO jQuery 2.x (edge)
use this clickToggle
plugin as toggle
function is removed from version 1.9
(function ($) {
$.fn.clickToggle = function (func1, func2) {
var funcs = [func1, func2];
this.data('toggleclicked', 0);
this.click(function () {
var data = $(this).data();
var tc = data.toggleclicked;
$.proxy(funcs[tc], this)();
data.toggleclicked = (tc + 1) % 2;
});
return this;
};
}(jQuery));
$('#target').clickToggle(function () {
alert('First handler for .toggle() called.');
}, function () {
alert('Second handler for .toggle() called.');
});
This format was removed in version 1.9, so you cannot use it - if you want this logic can be manually implemented or you can make use of the migration plugin
to include the migration plugin, after the inclusion of jQuery library add
<script src="http://code.jquery.com/jquery-migrate-1.2.1.js"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With