选择以下span jquery

发布于 2025-01-08 08:44:40 字数 703 浏览 0 评论 0原文

我必须循环遍历其中几个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

ぽ尐不点ル 2025-01-15 08:44:40

你应该这样做,

$('.eachLocation').each(function(index) {
    var address=$('span.LocationAddress', this).html();
});

这肯定会起作用......

you should do it this way

$('.eachLocation').each(function(index) {
    var address=$('span.LocationAddress', this).html();
});

this will work for sure...

冰魂雪魄 2025-01-15 08:44:40

locationAddress 不是每个Location 的同级。所以不要使用兄弟姐妹

$('.eachLocation').each(function(index) {     
    var address=$(this).find('span.LocationAddress').text();
});

locationAddress is not a sibling of eachLocation. So don't use siblings

$('.eachLocation').each(function(index) {     
    var address=$(this).find('span.LocationAddress').text();
});
旧伤慢歌 2025-01-15 08:44:40

我突然想到:您是否尝试过使用 .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

南七夏 2025-01-15 08:44:40

如果 HTML 不会改变,那么您可以直接定位地址:-

如果 span 包含普通文本

var address = $('.eachLocation div span.LocationAddress').text();

如果 span 包含 html

var address = $('.eachLocation div span.LocationAddress').html();

以其他方式,

$('.eachLocation span.LocationAddress').each(function() {
    var address = $(this).html();
});

If HTML, won't change then you can target the address directly:-

If span contains normal text

var address = $('.eachLocation div span.LocationAddress').text();

If span contains html

var address = $('.eachLocation div span.LocationAddress').html();

In other way,

$('.eachLocation span.LocationAddress').each(function() {
    var address = $(this).html();
});

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文