Reputation: 217
My html is:
<tr>
<td><select id = "delAppSelectApp" name="delAppSelectApp"><option value="--Select--"> --Select--</option></select></td>
<td><select id = "delAppSelectAppVers" name="delAppSelectAppVers"><option value="--Select--">--Select--</option></select></td>
<td><input type="submit" name="submitDelAppVers" id="submitDelAppVers" value="Delete Application Version" /></td>
</tr>
My script is:
$(document).ready(function(){
$("#delAppSelectApp").change(function(){
alert( $(this).nextAll("select").attr("id") );
});
});
I want the window to alert "delAppSelectAppVers", which is not happening. What am I doing wrong ? I've even tried the "siblings" function.
Upvotes: 2
Views: 522
Reputation: 220146
$(document).ready(function() {
$("#delAppSelectApp").change(function() {
alert( $(this).closest("td").next().find('select').attr("id") );
});
});
Here's a demo: http://jsfiddle.net/7twmJ/
Upvotes: 3
Reputation: 739
It's not working because the there is no "next" element (sibling) at the same level within the node xpath/axis. Try this:
$(this).parent.next().children("select:first").attr("id")
Upvotes: 1