Jquery – Access iFrame Elements

Iframes aren’t the best solution to most problems, but when you do need to use one it’s very handy to know how to access the elements inside it with Javascript.

jQuery’s contents() method makes this a breeze, enabling us to load the iframe’s DOM in one line like this:

	var iFrameDOM = $("iframe#someID").contents();
	//Now you can use <strong>find()</strong> to access any element in the iframe:
	//Slides up all elements classed 'message' in the iframe

Leave a Reply

Your email address will not be published. Required fields are marked *