如何获得有孩子的链接的文本? [英] How to get the text of a link which has children?

查看:58
本文介绍了如何获得有孩子的链接的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在试图弄清楚如何获取有孩子的链接的文本。
我的html看起来非常像这样:

I'm currently trying to figure out how to get the text of a link which has children. My html looks pretty much like this:

<a href="">
    The text I want to get
    <span> something I don't want to get </span>
</a>

我想只获得我想要的文字而不包括孩子们的文字。

有没有简单的方法呢?

I want to get only "The text I want to get" and not to include the children's text.
Is there an easy way to do it?

推荐答案

$("#mylink").clone()
        .children()
        .remove()
        .end()
        .text()

查找示例此处

这篇关于如何获得有孩子的链接的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆