jQuery selector wildcard within a string

jquery, jquery-selectors

Solution

You could do something like this:

$('a[href^="http://domain.com/"][href$="#foo"]');

That selects `a` elements having an `href` that starts with `http://domain.com/` and ends with `#foo`.

If you don't care about the `foo` part and only care about the hash, use this instead:

$('a[href^="http://domain.com/"][href*="#"]');

The second part of the select is the "contains" filter.

Problem

Links http://domain.com/[random]/#foo http://domain.com/[random]/bar How to select the links that start with http://domain.com/ and then wildcard ([random]) and then #?

Original source

Related problems