javascript - Find specific place in div where text occurs -
i have html:
<div id="score-data"> <h4>soccer league</h4> <span>14:00</span> teama - teamb <a href="/match/pveahz4u/?s=1" class="fin">3:0</a> <br> <span>14:00</span> teamc - teamd <a href="/match/oo61fezi/?s=1" class="fin">0:1</a> <br><span>15:00</span> teame - teamf <a href="/match/z3zkcxjn/?s=1" class="fin">3:0</a> </div>
this sample, there hundreds of identical html patterns within same div
. need use jquery find href
corresponding team. thought try like:
var = $("#score-data:contains('teamc')").closest('a').attr('href');
but returns undefined
, suspect because looking closest a
tag outer div
, doesn't help. how can jquery?
here's jsfiddle working sample.
var href = $("#score-data a").filter(function () { return this.previoussibling.nodevalue.indexof('teamc') > -1; }).attr('href'); alert(href);
links
$("#score-data a")
filter .filter()
previous (text) node's value this.previoussibling.nodevalue.indexof('teamc') > -1;
. .filter()
Comments
Post a Comment