jQuery extract hyperlinks with specific href

By Sam Deering

Simple jQuery code snippet to use jQuery selector to get all those href’s based on a wildcard search. I was just writing a jQuery selector to extract hyperlinks based on wildcard matches and thought I would share it on the blog.

//output all links on page that start with ""
$('#j4u-post a[href^=""]').each(function (i,v)


Now to add a wildcard into our selector we can do this:

$('#j4u-post a[href*=""]').each(function (i,v)

Using the *= essentially means “like” and the ^= means starts with. Thats it.

Free Guide:

7 Habits of Successful CTOs

"What makes a great CTO?" Engineering skills? Business savvy? An innate tendency to channel a mythical creature (ahem, unicorn)? All of the above? Discover the top traits of the most successful CTOs in this free guide.

No Reader comments

Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in JavaScript, once a week, for free.