jQuery:在成功时更改链接文本

时间:2010-09-17 16:16:45

标签: jquery

在showComments()中,ajax调用和成功我试过:

$('#showCommentLink').text("Hide");

我试图将文字从显示所有评论更改为“隐藏”而没有结果。

<a class='showCommentLink' href='javascript:showComments($displayWall[id]);' style='cursor: pointer;'>Show all $isThereAnyComments comments</a>

我错过了什么吗?

2 个答案:

答案 0 :(得分:3)

$('.showCommentLink')不是$('#showCommentLink')

#选择器用于ID,.选择器用于类。

答案 1 :(得分:2)

$('.showCommentLink').text("Hide");

您使用了#,它会查找ID。 “”寻找一个班级。

另外,你应该阅读onobtrusive javascript - 在你的href中运行该函数会破坏jquery的主要目的!