I have one scenario such that using while clicking a div I have to get the `id` of its outer div.

For example : 

```
<div class = "top-class" id="top1">
  <tr>
    <td><div id="1" class="xx"></div>
    <td><div id="2" class="xx"></div>
    <td><div id="3" class="xx"></div>
  </tr>
</div>

<div class = "top-class" id="top2">
  <tr>
    <td><div id="5" class="xx"></div>
    <td><div id="6" class="xx"></div>
    <td><div id="7" class="xx"></div>
  </tr>
</div>

```

Now on clickig `xx` I must get the `id` of div with class name "top-class" it belongs to. I have coded like this but didnt know how to get the id. Can anyone help me out with this?

```
$('.xx').click(function(){
     alert($(this).prevAll('.top-class').attr('id')); //code fails though
});

```