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

  • Home
  • SEARCH
  • 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 968515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:29:36+00:00 2026-05-16T02:29:36+00:00

I’m hoping someone can help me with the syntax for a jQuery selector. I

  • 0

I’m hoping someone can help me with the syntax for a jQuery selector. I just can’t get it to work!
I’m trying to select the input field that relates to the table row that contains a div with class span. Here’s the HTML:

<tbody>
  <tr><th scope="col"><label for="username">Username</label><br /><?php echo form_error('username');?></th></tr>
  <tr><td><input type="text" id="username" name="username" value="<?php echo set_value('username');?>"/></td></tr>
  <tr><th scope="col"><label for="password">Password</label><br /><?php echo form_error('password');?></th></tr>
  <tr><td><input type="password" id="password" name="password" /></td></tr>
</tbody>

If there is an error with either field a div will be created (echo form_error) which has a class of “form_error” and has text describing the error.

I want to select the text input if there is an error so that I can highlight by changing the CSS, e.g. changing the colour of the border to red.

This is the jQuery I tried but isn’t working:

$(document).ready(function() {
$("tr:has(.form_error)").next().children("td:input").css("border-color", "#C21312");
});

Any suggestions?

  • 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-16T02:29:36+00:00Added an answer on May 16, 2026 at 2:29 am

    You have two major errors. Allow me to break out your code:

    $("tr:has(.form_error)") // finds row containing element with form_error class
      .next() // move to the next row
      .children("td:input") // find a direct child of the row 
                            // that is both a td and input element
      .css("border-color", "#C21312"); // make border color red
    

    As Sarfraz pointed out, you need a space in the “td:input” selector – td elements are never form elements, and obviously you’re looking for an input child of the td element anyway.

    But that only exposes the second error: you’re not looking for a direct child of the row, you’re looking for a grandchild – yet children() will search only the immediate descendants of the context elements. What you really want to use is find()…

    $("tr:has(.form_error)") // finds row containing element with form_error class
      .next() // move to the next row
      .find("td :input") // find an input element descendant of the row 
                         // that has a td as its parent
      .css("border-color", "#C21312"); // make border color red
    

    Note that for your purposes, you don’t really need to use the :input selector – input would work just fine as well, since in the example you gave, it’s actually an <input> element you’re looking for… But if you plan on using other form controls as well, :input will give you slightly more flexibility.

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

Sidebar

Related Questions

No related questions found

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.