Pregunta

I would like to know how to get the number of element with a certain attribute on the second TR.

What I tried:

$("[Chk_RPQSelection_col=1] tr:nth-child(2)").length

$("tr:nth-child(2) [Chk_RPQSelection_col=1] ").length

Thanks for any help !

¿Fue útil?

Solución

no spaces in the selector :

$('tr:nth-child(2)[Chk_RPQSelection_col="1"]').length

will find all TR's that are the second children of a table looking like

<table>
    <tr Chk_RPQSelection_col="1"></tr>
    <tr Chk_RPQSelection_col="1"></tr> <!-- this one -->
    <tr Chk_RPQSelection_col="1"></tr>
    <tr Chk_RPQSelection_col="1"></tr>
    <tr Chk_RPQSelection_col="1"></tr>
</table>

<table>
    <tr Chk_RPQSelection_col="3"></tr>
    <tr Chk_RPQSelection_col="1"></tr> <!-- and this one -->
    <tr Chk_RPQSelection_col="4"></tr>
</table>

EDIT:

to count TD's with that attribute inside the second TR, you can do:

$('tr:nth-child(2)').find('td[Chk_RPQSelection_col="1"]').length
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top