selecting asp.net adjacent text boxes using jquery
I want to select an adjacent asp.net textbox which is inside a table cell using css class attribute.
The html is as below:
<td colspan="">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txt_zipcode" SetFocusOnError="true"
ErrorMessage="Zip Code" Display="None" ></asp:RequiredFieldValidator>
<asp:TextBox CssClass="txtbox zipcode" Width="40px" ID="txt_zipcode"
runat="server" MaxLength="5"></asp:TextBox>
</td>
<td class="txtcaption" align="right">
City:
</td>
<开发者_如何学JAVAtd>
<asp:TextBox ID="txt_city" CssClass="txtbox city" MaxLength="30" Width="120px"
runat="server" Text=""></asp:TextBox>
</td>
The jquery code is as below:
$(document).ready(function () {
$('.zipcode').next('input:text').hasClass('city');
});
The above code always return false value. I am trying to select City textbox which is below the zip code text box. Do you have solution to this problem?
next will search within siblings and the next input element is in next table cell which is not a sibling. Try this:
$(document).ready(function () {
alert($('.zipcode').parent().siblings().find('input:text').hasClass("city"))
});
精彩评论