How to find a previous class in a previous row and get it's value

How to find a previous class in a previous row and get it's value

Hello,

I have a button that is on every row, I need to find the value of a class that is in my heading.

I have the following that is returning "undefined" . I have this same code to find classes and it works fine.

var $item = $(this).parents("tr").prevAll(".lastitemno").eq(0).val();

The the class "lastitemno" has a value assigned by a cgi program, but the var "$item" is returning "undefined".
There can be any number of rows between the button and the class defined in the heading.