I want to get the iframe through the for statement. And I want to put different numbered html files in iframe. I've tried, but src doesn't work as a for statement. I've tried a lot, but it's too difficult for me. help me plz..
original code
const elements = document.getElementsByClassName("book"), bubbles = false;
const observer = new WebKitMutationObserver(function (mutations) {
mutations.forEach(attrModified);
});
for (var i = 0; i < elements.length; i++) {
observer.observe(elements[i], { attributes: true, subtree: bubbles });
}
function attrModified(mutation) {
const contentStyle = mutation.target.getAttribute("style");
const IsVisible = contentStyle.indexOf("block") != -1;
if (!IsVisible) {
const currentIframe = $(mutation.target).children("iframe");
currentIframe.attr("src", "./iframe_model/model01.html");
}
else {
const link = $(mutation.target).data("link");
const currentIframe = $(mutation.target).children("iframe");
currentIframe.attr("src", link);
}
}
code i want
const iframe = document.querySelectorAll(".if");
let currentPageNumber = 1;
for(var i = 0; i < iframe.length; i++) {
iframe[i].src="./iframe_model/model0" + currentPageNumber++ + ".html";
currentPageNumber++;
}
code i tried
const elements = document.getElementsByClassName("book"), bubbles = false;
const observer = new WebKitMutationObserver(function (mutations) {
mutations.forEach(attrModified);
});
for (var i = 0; i < elements.length; i++) {
observer.observe(elements[i], { attributes: true, subtree: bubbles });
}
function attrModified(mutation) {
const contentStyle = mutation.target.getAttribute("style");
const IsVisible = contentStyle.indexOf("block") != -1;
if (!IsVisible) {
let currentIframe = $(mutation.target).children("iframe");
let currentPageNumber = 1;
// currentIframe.attr("src", "./iframe_model/model01.html");
for(var j = 0; j < currentIframe.length; j++) {
currentIframe[j].src="./iframe_model/model0" + currentPageNumber++ + ".html";
currentPageNumber++;
}
}
else {
code comments
}
}