Question

$('a[xlink:href=#'+value.id+']').addClass("foo");

I have an svg which has <a xlink:href="#21" xlink:title="21"></a> arround the polygons.

What I'm trying to do is add a class to the a where the xlink:href matches that of value.id

Was it helpful?

Solution

You have to escpae the meta characters before using them as selectors by double backslash.

Do this:

$('a[xlink\\:href=#'+value.id+']').addClass("foo");

jQuery doc says:

To use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[\]^{|}~` ) as a literal part of a name, it must be escaped with with two backslashes: \. For example, an element with id="foo.bar", can use the selector $("#foo\.bar").

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top