Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting all mailto links with jQuery

I need a pattern that will traverse the document and get me all links that have mailto in their href:

<a href="mailto:[email protected]">text</a>

I could of course easily get all a elements ($("a")) and check each href attribute to see if it points to a mailto but I think that jQuery has some form of pattern matching that will allow me to do just that.

What is the best way to achieve that?

like image 243
Andreas Grech Avatar asked Nov 20 '09 14:11

Andreas Grech


1 Answers

$('a[href^="mailto:"]')

Double quotes are usually redundant, but needed in this special case, because : would otherwise be interpreted as the start of a pseudo-selector. So $('a[href^=mailto]') would also work, but in this particular scenario, the quotes are probably a neater way to go.

like image 169
David Hedlund Avatar answered Oct 14 '22 17:10

David Hedlund