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 7436295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:13:02+00:00 2026-05-29T10:13:02+00:00

I have a field like the following: <div class=control-group> <label class=control-label for=lname>Last Name</label> <div

  • 0

I have a field like the following:

<div class="control-group">
    <label class="control-label" for="lname">Last Name</label>
    <div class="controls">
        <input class="span3" type="text" id="lname" name="lname" placeholder="Last Name" value=""/>
    </div>
</div>

I’m trying the following jquery to validate some input and add the error class if needed:

var div = $("#lname").parent("div.control-group");
....
div.removeClass("success");
div.addClass("error");

Ideally I need to loop through several input and select fields to do my validation.

My current code isn’t adding the error class. Any idea why?

  • 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-05-29T10:13:02+00:00Added an answer on May 29, 2026 at 10:13 am

    You should use parents method instead of parent as

    var div = $("#lname").parents("div.control-group");
    div.removeClass("success");
    div.addClass("error");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following markup for my input fields: <div class=required> <label for=Name>Name <em>*</em></label>
I have the following mark-up: <fieldset> <div> <label class=editor-label>Question 1?</label> <input type=text class=editor-field />
I have dynamically generated code like the following: <div class=message-error error>The Message field is
I have the following: <div class=btn-group> <input disabled=disabled id=dialogType> <button data-toggle=dropdown class=dropdown-toggle> <span class=caret></span>
I have a model like the following one: public class TestModel{ public IList<Field> Fields
I have excluded a field like this in order to set it's label. class
I have the following structure in a form: <div class='full'> <div class='half'> <label>Book</label> <select
I have the following html form <div> <p>Field1</p> <input type=text name=fld_one id=fld_one value= />
I have the following (simplified) HTML structure <td> <DIV class=t-numerictextbox> <DIV class=t-formatted-value>$0.00</DIV> <INPUT id=MyObj_PropertyName
I have a datetime field like that. <field name=rel_date type=date indexed=true stored=true default=NOW multiValued=false/>

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.