如何通过jQuery中的href获取元素? [英] How to get an element by its href in jquery?

查看:484
本文介绍了如何通过jQuery中的href获取元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过jQuery或JavaScript中的href属性获取元素。这是可能的吗?

I want to get an element by its href attribute in jquery or javascript. Is that possible?

推荐答案

是的,您可以使用jQuery的

Yes, you can use jQuery's attribute selector for that.

var linksToGoogle = $('a[href="http://google.com"]');

或者,如果您的兴趣是使用某个网址链接开始使用属性开始选择器:

Alternatively, if your interest is rather links starting with a certain URL, use the attribute-starts-with selector:

var allLinksToGoogle = $('a[href^="http://google.com"]');

这篇关于如何通过jQuery中的href获取元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆