how to find previous dropdown value based on class name
i have a button and on 开发者_JAVA技巧the click event i want to read the value from a dropdown based on a class name. I want to grab the previous instance of this class.
i know i can do this to get the exact previous value but how do you add the class condition?
var teamId = $(this).prev().val();
prevUntil is doing exactly what you ask: $(this).prevUntil('some_selector')
Scratch that. prevAll allows you to pass in selector. You can also return the nearest matched sibling with :first
: .prevAll('.my_class:first')
.
An example
Actually you can add a selector as parameter of the prev() method. So something like
var teamId = $(this).prev(".myclass").val();
should work.
精彩评论