I have a page which contains a div.
CODE
<div id="main_data">My main div</div>
I am also hosting this page within an iframe at another page (Parent Page).
I have a function that hides/shows the div that runs when one clicks on a button.
I am calling the function from the page itself and from the parent page which host the page.
Right now i am using this code to access the “Main_data” div from the page itself
var element = $('#main_data');
And i am using this code to access the “Main_data” div from the parent page which host the page within an iframe.
The “graphFrame” is the ID of the iframe in the parent page
var element = $('#graphFrame').contents().find("#main_data");
That means i am duplicating code, and i don’t like it.
I am wondering if there is a way to access the DOM element with one line of code which will fit for both cases?
I don’t see much code is duplicated and I don’t think it’s very necessary to use this:
not tested