Jie Hart
Jie Hart

Reputation: 909

I cannot get jquery 'change' to work, what am I doing wrong?

I have tried ".change" and ".live change" but with no success. The code below is one of the many I have copied from googled requests for examples. I believe I need to use the "live" change because in my code I dynamiclly create the input field.

<!DOCTYPE html>
<html>
<head>
    <title>test change</title>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
</head>
<body>
    <input id='inurlprodcgs' type="url" name="urlprodcgs" autocomplete="off" required/>
</body>
    <script>
        if (typeof jQuery != 'undefined') {
            alert("jQuery library is loaded!");
        }else{
            alert("jQuery library is not found!");
        }
        $("input[type='url']").live('change', function(e) {
            alert("hide");
        });
    </script>
</html>

As you can see I have tested to see if jquery is loaded.

Upvotes: 0

Views: 260

Answers (2)

Bryan Rojas
Bryan Rojas

Reputation: 1

    <!DOCTYPE html>
<html>
<head>
    <title>test change</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
</head>
<body>
    <input id='inurlprodcgs' type="url" name="urlprodcgs" autocomplete="off" required/>
</body>
    <script>
        if (typeof jQuery != 'undefined') {
            alert("jQuery library is loaded!");
        }else{
            alert("jQuery library is not found!");
        }
        $("input[type='url']").change(function(e) {
            alert("hide");
        });
    </script>
</html>

Upvotes: -2

Adil Shaikh
Adil Shaikh

Reputation: 44740

because live is removed (as you are using 1.10) use .on()

$(document).on('change',"input[type='url']", function(e) {
            alert("hide");
});

Upvotes: 4

Related Questions