我想通过 jquery 或 javascript 中的 href 属性获取元素。这可能吗?
最佳答案
是的,您可以使用 jQuery 的 attribute selector为此。
var linksToGoogle = $('a[href="https://google.com"]');
或者,如果您感兴趣的是链接 start 与某个 URL,请使用 attribute-starts-with选择器:
var allLinksToGoogle = $('a[href^="https://google.com"]');
关于javascript - 如何在 jquery 中通过其 href 获取元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3105984/