Search code examples
jqueryiframeparent

jQuery - iframe loops all DIVS in parent window?


My site is using some iframes, when a specific link is clicked in one of the iframes I need to find all the other iframes in the parent page and refresh them.

In the past I've used the following, but that has been run in the parent.

$('div[id^="site-"]').each(function(i, obj) {
    location.reload();
})

Obviously this won't work when it's running in the iframe as the other iframes are in the parent. Is there anyway to find each div in the parent with an ID starting site- and refresh them ?

Thanks


Solution

  • I've got this working using the following in the iframe:

    frames = window.parent.document.querySelectorAll('[id^="site-"]');
    
    $.each(frames, function(index, item) {
        console.log ( item )
    });
    

    Each entry in the console.log is the element I require.