Rob
Rob

Reputation: 312

Jquery remove class failing

I have a upload script that is adding and extra upload button (that works fine), but the remove button does not work

var i = $("#AddFileInputBox div").size() + 1;
$("#AddMoreFileBox").click(function () {
    event.returnValue = false;
    if(i < MaxFileInputs)
    {
        $('<span><input type="file" id="fileInputBox" size="20" name="file[]" class="addedInput" value=""/><a href="#" class="removeclass small2"><img src="images/close_icon.gif" border="0" /></a></span>').appendTo(FileInputsHolder);
        i++;
    }
    return false;
});

$("body").on("click",".removeclass", function(e){
    event.returnValue = false;
    if( i > 1 ) {
            $(this).parents('span').remove();i--;
    }

}); 

Chrome console:

Uncaught TypeError: Object #<Object> has no method 'on' 

line: 113, which is

$("body").on("click",".removeclass", function(e){

Thanks for any help in advance

Upvotes: 0

Views: 236

Answers (2)

Hanna
Hanna

Reputation: 10753

You'll want to update your version of JQuery to at least version 1.7, as that is when .on() was introduced. Here is the documentation for .on(), which was introduced in JQuery version 1.7.

Also important to note is that the .size() method is deprecated as of JQuery 1.8, please use .length.

So either use JQuery 1.7, or if you would like to use the newest version of Jquery, replace all instances of .size() with .length.

Here is a working copy of your example. (Using JQuery 1.9.1)

Upvotes: 4

Rob
Rob

Reputation: 312

I fixed it with reverting to jquery 1.7 and it worked, thanks for all your help people.

Upvotes: 0

Related Questions