Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8957567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:01:11+00:00 2026-06-15T15:01:11+00:00

Using jQuery validation for ajax form submission and I would like to add a

  • 0

Using jQuery validation for ajax form submission and I would like to add a class to the errorContainer if any of the text inputs have a class ‘error’. Seems simple but I think it’s a scope issue?

if ($('#myInput').hasClass('error')) { 
  $('#errorContainer').addClass('foo'); 
}

I have placed this outside the submit handler, inside submit handler, outside of validation call, inside validation call… all to no avail. Has anyone done this simple task with success?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:01:12+00:00Added an answer on June 15, 2026 at 3:01 pm

    You can do this:

    if ($('input[type=text].error').length > 0) { 
      $('#errorContainer').addClass('foo'); 
    }
    

    The selector $('input[type=text].error') is going to return an array-like object even if there is only one match. So asking an array if it hasClass('error') doesn’t make sense.

    What you really want to do is put a container around your elements you want to check for the error class. You might already have a container like the form (if it is all the inputs on the form). Then you can do something like this:

    <form id="myForm">
      <input type="text" name="a" />
      <textarea name="b"></textarea>
      <input type="submit" value="Submit" />
    </form>
    

    With JavaScript:

    $(':input.error', '#myForm').length > 0
    

    Here is an example jsfiddle. Note that using the :input selector will more input types than just input which may be what you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form using jquery validation plugin. My submit button has an ajax
I am using jQuery and MVC to do form submission like this @using (Ajax.BeginForm(Orders,
I'm working on a form validation and submission using jQuery and AJAX. Now, most
I am using jquery validation plugin for form validation. I have added a custom
I'm using jQuery validation in ASP.net MVC. I would like to show validation summary
I am using JQuery to perform form submission through an ajax request. I use
I am creating a JavaScript / ajax comment form using the jQuery Validation Plugin.
I am creating a popup jquery ajax comment form using the jquery validation plugin.
I am creating a popup jquery ajax comment form using the jquery validation plugin.
I'm using asp.net mvc 3 with unobtrusive jquery validation. I have a form that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.