ash_dev15
ash_dev15

Reputation: 45

How to fix script after upgrading jQuery to 2.1.4?

I was using jQuery 1.8.3 and had this piece of script :

    $("[src*=plus]").live("click", function () {
        $(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>")
        $(this).attr("src", "../Images/minus.gif");
    });

    $("[src*=minus]").live("click", function () {
        $(this).attr("src", "../Images/plus-sign.png");
        $(this).closest("tr").next().remove();
    });

After upgrading to jQuery 2.1.4, this no longer works.

I get it that some functions like live is not supported anymore but I am unable to convert this piece to make it work.

Upvotes: 1

Views: 555

Answers (2)

depperm
depperm

Reputation: 10756

live is deprecated. Use on instead.

Upvotes: 1

k0pernikus
k0pernikus

Reputation: 66817

When upgrading jQuery you should use jQuery migrate.

This is offically recommended way in finding out what has been deprecated in jQuery.

If you’re upgrading from a version before 1.9, we recommend that you use the jQuery Migrate plugin and read the jQuery 1.9 Upgrade Guide, since there have been a lot of changes. It’s easy to use the plugin, just include it in your HTML file after jQuery and open your browser console to see the messages it generates:

<script src="http://code.jquery.com/jquery-2.0.0.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.1.1.js"></script>

You should also look into the jQuery upgrade guide.

Upvotes: 2

Related Questions