Reputation: 25
i have a toggle-script for the height of a list by clicking on a button. Problem is, it works for jQuery under 1.8.3. But my website using 2.1.4 at the moment, so what is wrong on the script?
$(document).ready(function() {
var $dscr = $('#oplist'),
$switch = $('#opbutton'),
$initHeight = 100; // Initial height
if( $dscr.height() <= $initHeight ) {
$switch.hide();
}
$dscr.each(function() {
$.data(this, "realHeight", $(this).height()+20); // Create new property realHeight
}).css({ overflow: "hidden", height: $initHeight + 'px' });
$switch.toggle(function() {
$dscr.animate({ height: $dscr.data("realHeight") }, 100);
$switch.text('show less');
},
function() {
$dscr.animate({ height: $initHeight}, 100);
$switch.text('show all');
});
});
Thank you very much in advance :)
Upvotes: 0
Views: 36
Reputation: 207557
https://api.jquery.com/toggle-event/
Note: This method signature was deprecated in jQuery 1.8 and removed in jQuery 1.9. jQuery also provides an animation method named .toggle() that toggles the visibility of elements. Whether the animation or the event method is fired depends on the set of arguments passed.
You need to implement your own toggle method now.
$switch.on("click", function () {
var isActive = !!$(this).data("active");
$(this).data("active", !isActive);
if (isActive) {
//active steps
} else {
//not active steps
}
});
Upvotes: 1