http://www.netindex.com/download/allcountries/
我想加载德国的 .ranking-item 类的 div。我将 div 定位为 .DE,然后尝试获取其第五个父级。
var ger = $('<div />').load( "proxy.php?url=http://www.netindex.com/download/allcountries/&mode=native&callback=complete .top-20-countries .DE");
尝试了 :parent、.parent()、.closest() 均无济于事。
最佳答案
HTML 看起来像这样:
<ol class="ranking">
<li class="ranking-item">
<a class="ranking-link" href="/download/2,91/Hong-Kong/">
<div class="figure">
<b class="figure-content">84.01</b>
<span class="figure-unit">Mbps </span>
</div>
<div class="ranking-content">
<div class="ranking-heading">
<i class="flag HK"></i>Hong Kong
</div>
<div class="ranking-chart country-list"><svg width="280" height="20">...</svg></div>
</div>
</a>
</li>
...
</ol>
<i>
的第五个父级标签是 <ol class="ranking">
元素,所以使用 .ranking:has(.de)
作为单个选择器传递到 .load()
:
var ger = $('<div />').load( "proxy.php?url=http://www.netindex.com/download/allcountries/&mode=native&callback=complete .ranking:has(.DE)");
关于JQuery:如何选择div的第五个父元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24611213/