【发布时间】:2020-12-23 16:56:55
【问题描述】:
(编辑: 我忘了要求不要使用 jQuery)
我正在尝试根据显示的文本而不是它们的类或 ID 来选择 html 按钮。
所有按钮都具有相同的 dom 结构和类。如以下示例中的follow 和unfollow 按钮:
<button class="user-actions-follow-button js-follow-btn follow-button btn" type="button">
<span class="button-text following-text">
Following
</span>
<span class="button-text unfollow-text">
Unfollow
</span>
</button>
我找到的最接近的解决方案是基于像getElementsByClassName、getElementById和:contains()这样的dom结构,但我想不通。
EDIT2:
jQuery 中的解决方案是$('span:hidden:contains(Follow)').parent();
但我正在寻找没有 jquery 的解决方案。
【问题讨论】:
标签: javascript jquery html dom