I have this html code and I was wondering how to get the text after span I tried using different methods and none worked.
<div id="nowplaying">
<div class="art200-left fixed-height">
<img class="art200" alt="Album Art" src="https://www.animenfo.com/radio/albumart/PCCA-02442.jpg" id="nowplaying_albumart" albumart class="albumart" hotkey="alt+=" />
<div class="float-container">
<div class="row">
<div class="span6"> <span class="text-semibold">Artist:</span> <span data-search-artist>Ueto Aya</span>
<br/> <span class="text-semibold">Title:</span> Namida no Niji
<br/> <span class="text-semibold">Album:</span> <span data-search-album>Namida no Niji/SAVE ME</span> (2007)
<br/> <span class="text-semibold">Album Type:</span> Theme Song Single
<br/> <span class="text-semibold">Series:</span> <span class="seriestag">Hotelier</span>
<br/> <span class="text-semibold">Genre(s):</span> Jdorama
<br/>
</div>
<div class="span6"> <span class="text-semibold">Duration:</span> <span id="np_timer" rel="214">3:34</span> / <span id="np_time" rel="265">4:25</span>
<br/> <span class="text-semibold">Rating:</span> 5.95 / 10 (234 rates)
<br/>
I'm trying to get the text Namida no Niji
, Theme Song Single
and other text after a span.
var elemBefore = $('span.text-semibold').filter(function() {
return $(this).text().match(/Title:/);
}),
relatives = elemBefore.parent().contents(),
index = relatives.index(elemBefore);
var after = relatives.eq(index+1).text();
elemBefore
is assigned the element relative to which you want the next node. relatives
is assigned a selector of all of the nodes with the same parent including itself. index
is assigned the index of elemBefore
within relatives
. after
grabs the text your test case is looking for.
The key to this is the contents
jquery method. It returns all of the child nodes (including text nodes). The eq
method is used to get the node after by index.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments