Hell yeah, this can be made shorter. But it would help to see your HTML in order to suggest a more generic traversal method.
The first thing that comes to my mind right now would be:
That’s the “contains” selector; alternatively you could use the “starts with” selector:
or the “contains prefix” selector (string separated by hyphens):