jan86 jan86 - 1 year ago 67
ASP.NET (C#) Question

Getting the contents of iframe

I'm currently trying to find the element located in an iframe. The hierarchy goes like this.

html > body > form#form1 > iframe#report-container > html > body > form#form1 > div > pageBreaker

(This is an aspx page, within an aspx page, that uses ascx file within an iframe).

I'm trying to find a good javascript or Jquery method of getting to the pageBreaker element.

Answer Source

You don't need jQuery to do this necessarily.

var iFrame = document.getElementById('iFrameId').contentDocument;
var desiredElement = iFrame.getElementById('pageBreaker');

Using the document API we can easily get the iFrame element and pull the content document out of it. Then it is trivial locating an element via its ID.