0

We're using an <object>-Tag to embed an SVG-Graphic. Now I would like to find an element inside this SVG-XML-Text using document.querySelector.

The call always returns null. Interestingly enough, if I use F12-DevTools (Chrome) and try to select the element with the same call in the console, it also returns null unless I expand the DOM in the Element-Hierarchy-View of the DevTools (by clicking). After I did that, the document.querySelector returns the Element I'm looking for.

Is there a way to "expand" the object from JavaScript so it is searchable with a querySelector?

1 Answer 1

1

I've found that if I first try to find the object and use it's contentWindow.document, then it will work:

document.querySelector('object').contentDocument.querySelector('[objId="xyz"]');

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.