1

Consider this example:

<table>
  <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>    
  </tr>  
</table>

How can I get reference to <td>2</td>? I need reference as I want to trigger event on it.

user4913383
  • 171
  • 1
  • 1
  • 11

3 Answers3

1

Just loop like:

$('table td').each(function() {
  if ($(this).text() === '2') {
    // trigger some event
    $(this).doTheThing();
  }
});
Hardy
  • 5,590
  • 2
  • 18
  • 27
1
$('td:contains("2")')

Selects the td with number 2 inside.

Blaž Zupančič
  • 2,176
  • 2
  • 13
  • 22
1

.filter()

Description: Reduce the set of matched elements to those that match the selector or pass the function's test.

$("td").filter(function() {
    return $(this).text() === "2";
}).trigger("whatever");
Andreas
  • 21,535
  • 7
  • 47
  • 56