Search code examples
javascriptdomframeset

Iterate over framesets in JavaScript?


How can I list all FRAMESET elements in an HTML document using JavaScript? I believe it to be possible to select these elements in the DOM tree because the DOM Inspector plugin for Firefox is able to list all the FRAMESETS in a page.


Solution

  • There's a window.frames collection, if that's what you mean.

    EDIT: Ah. For blowing away all frameset elements, getElementsByTagName:

    var framesets = document.getElementsByTagName('frameset');
    for (var i = 0; i < framesets.length; i++) {
      // optional test for whether framesets[i]'s hatesFreedom attribute is true or false
      framesets[i].parentNode.removeChild(framesets[i]);
    }
    

    Or jQuery, obviously:

    $('frameset[hatesFreedom=true]').remove();