在使用jquery的按钮之前,仅使用某个类选择

我有这个HTML标记,我想使用jQuery选择一些行。

当按下带有’cerrar’类的按钮时,我想在同一个按钮之前选择带有’隐藏’类3 tr

  Test   Test   Test   Test    <!-- ********* Select this  ********* -->  Test   Test   Test   Test    <!-- ********* Select this  ********* -->  Test   Test   Test    <!-- ********* Select this  ********* -->  Test   Test        ...  

你可以这样做:

 $('.cerrar').click(function(){ // Get all the tr's with hidden class before button var TRs = $(this).closest('tr').prevUntil("tr.main").andSelf(); });