I’m trying to access the text of some elements using jquery, but it seems that once the text is accessed, it is removed from the element so accessing again the same node will return undefined.
The jquery code is like follows:
theText = $("#quotes-content-wrapper").children()[x].childNodes[0];
where x takes values from 0 to $("#quotes-content-wrapper").children().length - 1
, depending on which element is clicked.
The HTML part:
<div id="quotes-content-wrapper">
<p id="q1" class="bot-quote">We believe that South Africa belongs to all the peopl [...]</p>
<p id="q2" class="bot-quote">I really wanted to retire and rest [...]</p>
<p id="q3" class="bot-quote">Education is the most powerfu[...].</p>
<p id="q4" class="bot-quote">To deny people their human rights is to challe[...]</p>
<p id="q5" class="bot-quote">Our human compassion binds[...]</p>
</div>
.bot-quote
has display:none;
, in case it matters somehow.
I am able to get the text from each paragraph once, but when I get back to any of them, they don’t have the text content anymore. Is this normal behavior of .children()[x].childNodes[0]
?
Sorry if I haven’t been to clear. Please ask if you don’t understand what I meant.