How to popup an alert when every cell in a table has been clicked?

If you’re wanting to set each cell to have a red background individually on click it would be done like this and will alert after all 5 have been clicked.

$('#one, #two, #three, #four, #five').click( function() {
    if($('.redbg').length == 5)
  background: red;
<script src=""></script>
    <td id="one">1</td>
    <td id="two">2</td>
    <td id="three">3</td>
    <td id="four">4</td>
    <td id="five">5</td>

Also, as T.J. Crowder pointed in the comments below. Starting an ID with a numeric value is invalid for CSS. You can do that with with class identifiers, but not IDs. I’ve changed your IDs in this example.

Browse More Popular Posts

Leave a Comment