Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

116
Views
I want to change the src value through a for statement

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
            }
            
        }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!