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?