E
E
Eugene2018-12-03 19:09:09
JavaScript
Eugene, 2018-12-03 19:09:09

How to manipulate svg which is connected via object tag?

Tell me how you can manage the file connected via object svg.

It is necessary through js to change the color and position of the objects of the svg file.

The file itself is connected like this:

<object type="image/svg+xml" data="images/bnr/hotel.svg" class="backBg_item_oj bnrPolygon_in_1"></object>

Inside the file, elements are separated by . Can't access element by its id. <g class="..."><path id="..."/></g>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-12-03
@djon_pulse

Can't access element by its id.

How do you do it? Suddenly wrong? Why didn't they show it?
You can’t just access by id (or using any other selector), external SVGs have a separate DOM tree, it is available through the contentDocument property of the corresponding object, i.e.:
const
  svgDocument = document.querySelector('object').contentDocument,
  element = svgDocument.querySelector('здесь уже можете указывать нужный id или что там вам надо');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question