1
I need to get the text that is contained between the tags span
.
That’s the structure I’m running through:
<table>
<thead>
</thead>
<tbody>
<tr>
<td colspan="9" class="questiontext">
<p>
<span>TEXTO A SER COPIADO 1.</span>
</p>
<p>
<span>O objeto de estudo da lógica é:</span>
</p>
</td>
</tr>
<tr>
<td colspan="9" class="questiontext">
<p>
<span>TEXTO A SER COPIADO 2.</span>
</p>
<p>
<span>É um sistema de normas, princípios e valores...</span>
</p>
</td>
</tr>
</tbody>
</table>
And this is the code I’m using to search for but doesn’t return the values as they should:
var quest = document.querySelectorAll('td[class^=questiontext] > p:nth-child(1)');
var valores = [];
for (var i = 0; i < quest.length; i++)
{
valores.push
(
$(quest[i]).find( "span" )
);
}
console.log(quest);
console.log(valores);
What am I missing?
P.S. I have to take the values because the idea is in the future to take those values to mark the spans
with repeated contents.
Oops! You’re right! So I changed the search variable to
quest
within thefor
and added.text()
to the code. Therefore, withinvalores.push( )
was like this:$(quest[i]).find( "span" ).text()
. Thanks @Sergio!– GOliveira
@Gabrieloliveira could use it too:
quest[i].querySelector("span").textContent
– Sergio
Yes, really! It worked here! It really needed it. Thank you @Sergio! ;)
– GOliveira