欢迎各位兄弟 发布技术文章
这里的技术是共享的
eq
method to reduce the matched set of elements to one at a specific index:
$(this).siblings(".bar").eq(0).text()
That will select the first element in the set. In your case, you could simply use prev
, as the element you're looking for comes directly before the clicked element:
$(this).prev(".bar").text()
The problem with the array notation method you were using is that it returns the actual DOM node contained within the jQuery object, and that's not going to have a text
method. eq
is the equivalent jQuery method to do this.
来自 http://stackoverflow.com/questions/7309080/how-to-select-only-one-sibling-with-jquery