Working With Elements Inside An iFrame In An Html Page

Working with elements inside an iFrame in an html page when you want to have a new page load as an HTML instead of using ajax calls to load appending an html page to the existing page and using css to display it.

Step 1. in index.html page of your application including as many iframes as possible in following manner

you can replace “blank.html” by your page source(src=”example.html”).now when you expand your iframe in the developer tool to see the children element tags in the DOM tree, the first children you may see is
#document.

that is because you are using your iframe src to access a different page from your current page.
To go inside that page and play with the new page’s elements we use “.contents()” .
This method doesn’t accept any arguments and you can use this method in the following manner:

$(‘#MYFRAMEID’).contents().find(‘.my-iframe-body’).addClass(‘access-inside-iframe’);

Also if you apply css in your css file to an DOM element inside an iframe, you won’t be able to as HTML doesn’t allow you to do so.
Here also we can use .content() in the following manner:

$(‘#MYFRAMEID’).contents().find(‘.my-iframe-body’).addClass(‘access-inside-iframe’).css(‘font-weight’,’bold’);

look whether it is supported in IE or not

Dwarika Dhish Mishra

My name is Dwarika Dhish Mishra, its just my name and I am trying to bring the worth of my name in to actions and wants to be the solution not the problem. I believe in spreading knowledge and happiness. More over I am fun loving person and like travelling a lot. By nature I am a tester and a solution maker. I believe in the tag line of http://ted.org “Idea worth spreading” . For the same, I have created this blog to bring more and more learning to tester fraternity through day to day learning in professional and personal life. All contents are the part of my learning and so are available for all..So please spread the contents as much as you can at your end so that it could reach to every needful people in testing fraternity. I am pretty happy that more and more people are showing interest to become the part your Abode QA blog and I think this is good sign for us all because more and more content would be before you to read and to cherish. You may write or call me at my Email id: dwarika1987@gmail.com Cell: 9999978609

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.