Uncaught TypeError: element.removeClass is not a function In Jquery [duplicate]
Asked Answered
F

1

12

I Using This Sample For Validate My form, But Got this Error:

Uncaught TypeError: element.removeClass is not a function says removeClass() Is Not Function !! I'm confused

My Js Code :

$(function () {
            var form = $('#CompanyStep')
              , formData = $.data(form[0])
              , settings = formData.validator.settings
              , oldErrorPlacement = settings.errorPlacement
              , oldSuccess = settings.success;

            settings.errorPlacement = function (label, element) {

                debugger;
                oldErrorPlacement(label, element);

                label.parents('.form-group').addClass('has-danger');
                label.addClass('text-danger');
                element.addClass('form-control-danger');
            };

            settings.success = function (label, element) {

                debugger;

                label.parents('.form-group').removeClass('has-danger');
                label.parents('.form-group').addClass('has-success');
                element.removeClass('form-control-danger');
                element.addClass('form-control-success');


                oldSuccess(label, element);
            };
        });
Flesh answered 5/1, 2017 at 22:25 Comment(9)
is label.parents('.form-group') a jquery object?Lotic
What is element? How is the method called? My guess is, it is not a jQuery object.Zadoc
@Loaf And how do yu get that when the code above does not show the method being called.... element is an argument and we do not see how it is setZadoc
lable Object no problem, Just removeClass() and addClass()Flesh
why says addClass or removeClass is not function()Flesh
Maybe try $(element).removeClass('form-control-danger') instead.Identical
@loaf Thanks So Much My Friend Fixed :)Flesh
@SoheilAlizadeh You're welcome :)Pithecanthropus
use .removeClass, not .RemoveClassPalatalized
P
25

Posting my comment as answer

Instead try:

$(element).removeClass('form-control-danger');
Pithecanthropus answered 5/1, 2017 at 22:42 Comment(2)
Ok, why does this work though?Fixation
@Telarian this is because what they were passing into setting.success for element was not a jquery object, so wrapping it around $() allows you to use removeClass() which is a jQuery function. I cannot tell 100% but it was probably just a DOM object. jQuery will take any DOM object to the main $() function, allowing you to use jQuery functions/etc on it.Pithecanthropus

© 2022 - 2024 — McMap. All rights reserved.