7

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 #?

ssilas777
  • 9,672
  • 4
  • 45
  • 68
Joseph
  • 1,734
  • 6
  • 29
  • 51
  • 1
    Hint: It contains ^= $=. – Rob W Jul 13 '13 at 21:49
  • 1
    @RobW Yes I have seen those, please read the question though because it is not a duplicate. – Joseph Jul 13 '13 at 22:07
  • 1
    I second that this is NOT a duplicate. Although similar to the linked question, there is one absolutely vital difference: this question is asking about a wildcard selector WITHIN the selector string. The other question, and the answers to it, only address a) wildcard at the end of the selector (selector starts with), b) wildcard at the beginning of the selector (selector ends with) or c) wildcard at both ends (selector contains). It does NOT address d) wildcard in the middle of selector, as is being asked here. – ibrewster Jun 16 '14 at 18:55

2 Answers2

12

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.

Jason P
  • 26,984
  • 3
  • 31
  • 45
0

Something like this?

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

Take a look at StartWith selector

Oleksii Aza
  • 5,368
  • 28
  • 35