选择以下span jquery
我必须循环遍历其中几个 eachLocation
Div,其中包含各个位置及其地址。
$('.eachLocation').each(function(index) {
var address=$(this).siblings().find('span.LocationAddress').text();
});
我没有得到任何地址价值???我做错了什么吗?
<div class="eachLocation" >
<div class="LocationCounter">1.</div>
<div class="LocationInfo">
<span class="LocationName">Kay Kay Center</span><br/>
<span class="LocationAddress">
1019 fairfax road, Bellevue, NE 68005
</span><br/>
</div>
</div>
I have to loop through several of these eachLocation
Div which holds various places and their addresses.
$('.eachLocation').each(function(index) {
var address=$(this).siblings().find('span.LocationAddress').text();
});
I am not getting any value for address??? Am I doing something wrong?
<div class="eachLocation" >
<div class="LocationCounter">1.</div>
<div class="LocationInfo">
<span class="LocationName">Kay Kay Center</span><br/>
<span class="LocationAddress">
1019 fairfax road, Bellevue, NE 68005
</span><br/>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你应该这样做,
这肯定会起作用......
you should do it this way
this will work for sure...
locationAddress 不是每个Location 的同级。所以不要使用
兄弟姐妹
locationAddress is not a sibling of eachLocation. So don't use
siblings
我突然想到:您是否尝试过使用
.html()
而不是.text()
? source 另外我认为你的意思是.children
而不是.siblings< /代码>
Off the top of my head : Have you tried using
.html()
instead of.text()
? source Also I think you mean.children
not.siblings
如果 HTML 不会改变,那么您可以直接定位地址:-
如果 span 包含普通文本
如果 span 包含 html
以其他方式,
If HTML, won't change then you can target the address directly:-
If span contains normal text
If span contains html
In other way,