Jquery find table cell where value is X
Asked Answered
C

2

14

I am trying to find a <td> where the value is 5. It is a calender so there will only be one 5 value.

Cowskin answered 5/10, 2012 at 13:2 Comment(0)
B
24

You can use filter method:

$('td').filter(function(){
    return $(this).text() === '5'
})
Benzvi answered 5/10, 2012 at 13:6 Comment(2)
@welovedesign Why not? For this case there is no difference between == and ===.Benzvi
The three === is to do explicit comparison, and disallow implicit comparison. Always use ===, as it is very unstable to rely on implicit conversions JavaScript will do for you on the fly.Deweese
D
9

Use the :contains selector:

var td = $("td:contains('5')");

Edit: This will also select the td with 15 and 25, if you want exact 5, then use the .filter method as the other answer said.

Decapod answered 5/10, 2012 at 13:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.