Myles
Myles

Reputation: 812

jQuery toggle deprecated what to use?

currently updating jQuery for a client and it seems toggle is deprecated. Should I attempt to use iteration instead?

Consider:

jQuery(document).ready(function(){
            var autoHide = function(){jQuery('#empty').trigger('click');}

            jQuery('#empty').toggle(function()
                    {
                        jQuery('html').bind('click',autoHide);
                        jQuery('#drop').animate({'height':'210px'},'slow');
                        jQuery(this).removeClass();
                        jQuery(this).addClass('downed');
                        jQuery('#drop').css('border-top','3px solid #fff')},
                    function()
                    {
                        var dropthis = jQuery(this);
                        jQuery('html').unbind('click',autoHide);
                        jQuery('#drop').animate({'height':'19px'},'slow',function(){
                            dropthis.removeClass();
                            dropthis.addClass('upped');
                        });
                        jQuery('#drop').css('border-top','none')
                    });

            jQuery("#drop div:not('#empty')").click(function(){
                jQuery('#drop').css('opacity','0.3');
            });
        });

An example of how iteration can be used is seen here: https://forum.jquery.com/topic/beginner-function-toggle-deprecated-what-to-use-instead

Is this a good alternative? If so, could you show me how I can apply it to my code? If not, could you provide a better alternative and justify your reasoning?

Any examples/fiddles/modifications to my code are welcome! Cheers, Myles

Upvotes: 1

Views: 2521

Answers (1)

Jai
Jai

Reputation: 74738

You can use jQuery Migrate Plugin:

from the documentation:

We have created the jQuery Migrate plugin to simplify the transition from older versions of jQuery. The plugin restores deprecated features and behaviors so that older code will still run properly on jQuery 1.9 and later. Use the uncompressed development version to diagnose compatiblity issues, it will generate warnings on the console that you can use to identify and fix problems. Use the compressed production version to simply fix compatibility issues without generating console warnings.

you can add this library:

<script src="your jquery library"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>

Fiddle with jQuery 1.11
Fiddle with jQuery 1.9.1

Upvotes: 1

Related Questions