Satpal's answer is pretty good (I like that the selector is restricted to only <a>
elements; that will be a little faster than searching the whole DOM).
I would like to suggest, though, that you use multiple data attributes. For example:
<a data-foo="abc" href="#">I'm Matched</a>
<a data-foo="abc" data-foo-bar="abc" href="#">I'm Matched Too</a>
<a data-foo="abc" data-foo-bar-baz="abc" href="#">I'm Matched Too</a>
<a data-bar-foo="abc" href="#">I'm Not Matched</a>
Or classes:
<a class="foo" data-foo="abc" href="#">I'm Matched</a>
<a class="foo" data-foo-bar="abc" href="#">I'm Matched Too</a>
<a class="foo" data-foo-bar-baz="abc" href="#">I'm Matched Too</a>
<a data-bar-foo="abc" href="#">I'm Not Matched</a>
In in this way, you can match one one thing (either data-foo
or class foo
), and get the specificity you need as well.