Question: I am trying to make all the table cells equal to the image size, but for some reason, they won't be set to it.

<http://jsfiddle.net/gzkhW/>

HTML(shortened a bit)

```
<table>
    <tr>
        <td><img src="http://i.imgur.com/CMu2qnB.png"></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>

</table>

```

CSS

```
table {
    border:1px solid black;
}
td {width:206px;
    height:214px;
    border:1px solid black;
}

```

Answer: 
You would like to do these:

1. You can directly select using `.slide`.
2. Check the length of `nextUp` instead.

Try this, seems to be a workaround:

**JS**

```
$('.next').click(function() {
    var current = $('.slide');
    var nextUp = $('.slide').next('.hello');

    if( nextUp.length == 0 ) {
        $('div.hello:first').addClass('slide');
        $('div.hello:last').removeClass('slide');
    } 
    else {
        $(nextUp).addClass('slide');
        $(current).removeClass('slide');
    }
});

```

**[JSFIDDLE DEMO](http://jsfiddle.net/c4ZNm/15/)**
You code have some issues. First, `.has` check if the element has descendant that match the selector. You just need to combine the selector to `.hello.slide`.

```
var current = $('.hello.slide');

```

---

You can then reuse that variable to target the next element.

```
var nextUp = current.next('.hello');

```

---

You need to check the length to know if it found something, not an empty string.

```
 if( nextUp.length === 0)

```

---

You also don't need to wrap your `current` and `nextUp` in a jQuery element, they already are a jQuery element.

```
nextUp.addClass('slide');
current.removeClass('slide');

```

---

Final code :
============

```
$('.next').click(function() {
    var current = $('.hello.slide');
    var nextUp = current.next('.hello');

    if( nextUp.length === 0) {
        $('.hello:first').addClass('slide');
        $('.hello:last').removeClass('slide');
    } else {
        nextUp.addClass('slide');
        current.removeClass('slide');
    }
});

```

Fiddle : <http://jsfiddle.net/c4ZNm/14/>