How to replace .toggle function since deprecated with add/remove class and slide up/down of siblings?
Hi, I'm a beginner. I have this code who works fine but is pointed as deprecated by jQuery migrate. How can I change it?
- ! jQuery(".toggle_title").toggle(
- function(){
- jQuery(this).addClass('toggle_active');
- jQuery(this).siblings('.toggle_content').slideDown("fast");
- },
- function(){
- jQuery(this).removeClass('toggle_active');
- jQuery(this).siblings('.toggle_content').slideUp("fast");
- }
- );
Maybe something like this will do the trick but as
$.fn.toggleClick is not a function it won't work (maybe I need to put the first part in another file/folder?:
- $.fn.toggleClick = function() {
- var functions = arguments,
- iteration = 0;
- return this.click(function() {
- functions[iteration].call(this);
- iteration = (iteration + 1) % functions.length;
- });
- }
- $(".toggle_title").toggleClick(function() {
- $(this).addClass('toggle_active');
- $(this).siblings('.toggle_content').slideDown("fast");
- }, function() {
- $(this).removeClass('toggle_active');
- $(this).siblings('.toggle_content').slideUp("fast");
- });