Y
Y
yarovikov2019-04-07 00:38:06
JavaScript
yarovikov, 2019-04-07 00:38:06

Is it possible to access path inside svg sprite using js?

Hi all.
There is the following:
Part of the sprite:

<symbol id="electric">	
  <path id="back_light" d="M1026.6,144.9l-4-0.7l-3.4.5l-2.9,17..." />
  <path id="front_light" d="M1026.6,144.9l-4-0.7l-3.4.5l-2.9,17..." />
  ..
</symbol>

Markup:
<svg class="moto-part moto-part-electric">
  <use data-id="electric" xlink:href="images/moto.svg#electric"/>
</svg>

I need to assign classes using js to path inside symbol. Is it possible to do this with this approach?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sayapinant, 2019-04-07
@sayapinant

Maybe. Everything is done through DOM elements. Look at specialized sites for how to implement this. This is discussed in detail here. And here too.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question