简体   繁体   English

如何在jquery中选择具有特定类名和唯一“名称”属性的按钮?

[英]How to select a button which has a certain class name and a unique “name” attribute in jquery?

I'm trying to create a comment system. 我正在尝试创建评论系统。 In this comment system, when a user a posts a reply to a comment, I wish to display a button called toggle replies - but this is only if it doesn't already possess replies that is. 在此评论系统中,当用户发布对评论的回复时,我希望显示一个名为“切换回复”的按钮-但这仅是当它还没有回复时。 If there are already replies to the comment, then I don't want to hide the replies toggle button. 如果已经有评论回复,那么我不想隐藏回复切换按钮。

This button has althe class .repliestogglebutton , and has a name which is the same as the comment id of the comment to which the reply is being posted. 此按钮的类.repliestogglebutton ,其名称与将回复发布到的评论的评论ID相同。

This is the html for the button: 这是该按钮的html:

'<button class="repliestogglebutton" name="'.$commentId.'" style="display:none">toggle all replies</button>';

What can I use to select it and toggle it in jQuery? 我可以用来选择它并在jQuery中切换它吗? I'm writing this in the success function in my ajax that I'm using to post the reply. 我正在用我的ajax的成功函数编写该代码,用于发布回复。

您可以使用:

$(".repliestogglebutton[name='.$commentId.']")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM