如何使用<a> tag in the .text() attribute? jQuery

时间:2016-02-20 19:48:30

标签: jquery html tags element

I have $userMsg.text('@' + msg.user + ': ' + msg.txt), and I want to make the user's name clickable, so that, for example, I could direct the page to the user's profile. However, when I throw <a> tags around msg.user, it doesn't seem to work. How can I accomplish this?

1 个答案:

答案 0 :(得分:0)

$.text()就是那个 - 文字。相反,请使用.html()

$userMsg.html('<a href="' + user.profile + '">@' + msg.user + '</a>: ' + user.msg)