如何在jQuery中获取链接的文本

时间:2017-06-04 21:43:53

标签: jquery html

我的目标是在链接本身创建副本之后显示链接的文本或内部html。

此时,当鼠标悬停在某个链接上时,我可以在链接后显示文字TEST

.link
{
   color:aqua;
   text-decoration: none;
   background-color: none;
}
.link:hover span {display:none;
.link:hover:after {content:"TEST";}

Python Samples

但是,我希望文本是“CoDe”。在使用jQuery链接后,如何显示链接本身的实际文本?

我曾尝试将hovered链接的内容记录到控制台,但这不起作用:

$('#link').hover(function() {
    console.log($(this).text());
});

我做错了什么?如何获取链接的文本并使用jQuery更改link:hover:after的内容?

0 个答案:

没有答案