I'm managing a tree of iFrames (all nested on a page) by id
and src
, so for a given src
I can return an array of elements leading to this iFrame, like so:
["document", "123123", "dasd321"]
Since the number of elements in my array is dynamic, I would now like to construct a selector to retrieve the window to send a postMessage to. So I would need something like this:
document
.getElementById("123123").contentWindow
.getElementById("dasd321").contentWindow
...
... postMessage({"foo":"bar"}, window.location.href);
to be constructed dynamically.
Question:
Is it possible at all to generate a dynamic selector by looping over an array? If so or if not, how would I go about this?
Thanks!