MultiDev
MultiDev

Reputation: 10649

Which function here has been deprecated?

I am using jQuery 1.11.0, and this short toggle code works well as long as I am loading jquery-migrate. When I don't load the jquery-migrate file, I don't see any js errors, but no text is shown on the page. What's breaking it?

jQuery(function ($) {
    $(".toggle_content").hide();
    $("h4.toggle").toggle(function () {
        $(this).addClass("clicked");
    }, function () {
        $(this).removeClass("clicked");
    });

    $("h4.toggle").click(function () {
        $(this).find(".toggle_icon").toggleClass("fa-rotate-270 norotate");
        $(this).next(".toggle_content").slideToggle();
    });

});

Upvotes: 1

Views: 89

Answers (1)

Rory McCrossan
Rory McCrossan

Reputation: 337694

The deprecated function here is toggle(). It still exists, but it no longer accepts two functions to be executed alternately as your code attempts. In your case, you can replace it with toggleClass:

jQuery(function($){
    $(".toggle_content").hide();
    $("h4.toggle").click(function(){
        $(this)
            .toggleClass("clicked")
            .find(".toggle_icon").toggleClass("fa-rotate-270 norotate").end()
            .next(".toggle_content").slideToggle();
    });
});

Upvotes: 4

Related Questions