Y
Y
Yaroslav IKARUS2015-11-09 15:57:23
JavaScript
Yaroslav IKARUS, 2015-11-09 15:57:23

How to addClass to svg element?

There is svg-ha (this is, if you're interested, a map of the city). When I click on a map segment (it has the .region class ), I want the .active class to be added to it . On the screen itself svg and jquery code.
35f3525596.jpg
But for some reason, the class does not want to be added to this case, despite the fact that the object comes to $ (this).
Console screenshot:
e9f5af04fb.jpg
What needs to be done so that it still adds a class to the map segment?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
Ivan Ignatiev, 2015-11-09
@yar-ikarus

Try $(this).attr('class', 'region active');

V
Vitaly Kirenkov, 2015-11-09
@DeLaVega

I suffered for a long time with this crap ... As a result, I was able to master it by:
.attr("class", "your classname")

M
monochromer, 2015-11-09
@monochromer

Try using the jQuery attr() function or js native setAttribute() and classList .

S
Sergey Zhukov, 2015-11-09
@Adobe

I literally struggled with this issue today as well. attr() method only saves. No other way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question