in multiple iframe target only one iframe

2019-08-27 19:50发布

问题:

  1. Index HTML has Multiple iframes 
  2. If iframes has xyz class ("I will add/remove a class from Index HTML and I will add a class to anyone of iframe")
  3. if the iframe has xyz class  only in that iframe make h2 tag color red
  4. if I remove xyz class from iframe make h2 tag normal color

sample HTML file in git : https://github.com/hiraghuak/iframe

My function inside iframe : 

<script>
    $(function () {
        var iframes = parent.document.getElementsByTagName("iframe");
        console.log(iframes + ' iframe');
        for (var i = 0; i < iframes.length; i++) {
            var iframeGetAttribute = iframes[i].getAttribute("class");
            console.log(iframeGetAttribute + ' iframe GetAttribute');
            if (iframeGetAttribute == 'xyz') {
                // ITS ALL WORKING FINE 
            }
        }
    });
</script>

Thank you