I have the following HTML and I need to get the first div parent of the object (collapse)

If this parent has a class of (ZeroClass) .. I want to have the next div parent .. 

```
<div>
  <div id = "DeadCode">
    <div class = "ZeroClass">
      <table class = "zeroTable">
         <...tableData...>
      </table>
    </div>
  </div>
</div>

```

the jQuery Function :

```
function ResizeGrid(){
    var collapse = $(".zeroTable").parent();

    if ($(collapse).hasClass("ZeroClass")) {
        collapse = $(collapse).parents($("div"));
    }
}

```

Everything goes fine but when passing through the if statement, it makes Collapse Null .. any ideas?