decorate elements by id (simple script)

decorate elements by id (simple script)

hey guys im trying to do a simple decoration for my form...the array contains the id of my fields and im trying to add a class to the fields and lables but im having no luck in it working...can anyone help me on why i cant get this to work...thank you

  1. var elements = {'username', 'email_address', 'confirmed_email_address', 'password', 'confirmed_password'};

    function decorate_form_errors(elements)
    {
        $.each(elements, function(id)
        {
            $("label[for!='" . id . "']").addClass('label-error');
           
            if ($("#" . id).is("input"))
            {
                $("#" . id).addClass('input-error');
            }
        });
    }

    decorate_form_errors(elements);