1
How do I access the next text td
within the iteration of loop
?
I need to check the next text TD
(of the next TR) after the TR
current of loop
.
In the first row of td
(administration), ie I want to find the next TD that has the text Administration through the loop but could not with the function next()
, someone help me?
$("tr td:first-child").each(
function(index) {
var texto = $(this).closest("tr td").text();
console.log(texto);
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<table>
<tr>
<td>administração</td>
<td>teste1</td>
<td>teste2</td>
</tr>
<tr>
<td>administração</td>
<td>teste3</td>
<td>teste4</td>
</tr>
<tr>
<td>administração</td>
<td>teste5</td>
<td>teste6</td>
</tr>
<tr>
<td>Empresas</td>
<td>teste7</td>
<td>teste8</td>
</tr>
<tr>
<td>Empresas</td>
<td>teste9</td>
<td>teste10</td>
</tr>
</table>
</body>
</html>
You have to improve this question, it is poorly formulated and difficult to understand.
– Sam