How do I access input value (inside div) just before a table?

How do I access input value (inside div) just before a table?

I have a few tables with the class name "gridview". Right before every table there's a DIV that's holding a text input. I already have a loop going through elements in the table and I thought I could make use of the same loop by also picking up what is written in the text input right before every table.

  1. </div><input class="txtNote" id="txtNote1" name="txtNote1" type="text"/><div>
  2. <table class="gridview" id="gridView1"></table>
How do I find this input located in the previous element before the table? I would need to get the value of that input, and doing this inside the function that's already processing elements in the table.

I have tried this:

  1. $(".gridview").each(function () {
  2. $(this).prev().find("input").val(); //Undefined
  3. //...other code, accessing elements inside table
  4. });

It says "Undefined", so it doesn't work. What is the right way to do this?

I guess I could create a separate function searching for all inputs with the same class, but I thought there might be a way to make use of the same loop/function that is already processing the gridview/table.