views:

59

answers:

3

i want to get an element by it href attribute in jquery or javascript, is that posible??

thanks!

+1  A: 

Yes.

$('a[href=\'http://google.com\']')

http://api.jquery.com/attribute-equals-selector/

Mark
Your protocol is missing the `//`.
patrick dw
OK, thanks. :).
Mark
+1  A: 
var myElement = $("a[href='http://www.stackoverflow.com']");

http://api.jquery.com/attribute-equals-selector/

Adam
You're missing the closing `]`.
patrick dw
Oops. I added it in. Thanks!
Adam
+10  A: 

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"]');
BalusC
+1 - The only answer without typos.
patrick dw
thanks to all, is what I wanted! :)
eos87