I have a easy function but it have a redundant content.function showHide(link,divObject){    if($(window).width() > 992) {        $( divObject ).slideToggle(slow,function(){            if ($(this).is(':visible')) {                $(.component-header).removeClass( arrow-down ).addClass( arrow-up );                $(link).text('Ukryj');            } else {                $(.component-header).removeClass( arrow-up ).addClass( arrow-down );                $(link).text('Poka');            }        });    } else {        $( divObject ).slideToggle(slow,function(){            if ($(this).is(':visible')) {                $(link).removeClass( arrow-down ).addClass( arrow-up );                $(.button.show-hide).text('Ukryj');            } else {                $(link).removeClass( arrow-up ).addClass( arrow-down );                $(.button.show-hide).text('Poka');            }        });    }}
Redundant code in javascript toggle function
javascript;jquery
Try this:function showHide(link,divObject){  $(divObject).slideToggle('slow', function() {    var isLarge = $(window).width() > 992,        classTarget = isLarge ? $('.component-header') : $(link),        textTarget = isLarge ? $(link) : $('.button.show-hide'),        text = $(this).is(':visible') ? 'Ukryj' : 'Poka';    classTarget.toggleClass('arrow-down arrow-up'); // see (*)    textTarget.text(text);  }}(*) Don't remember if 2 classnames can toggle inversely at once. If it don't work, merely chain 2 unary toggleClass():    classTarget.toggleClass('arrow-down').toggleClass(' arrow-up');