Lets say I have a page on the same domain that I put inside an iframe. In the iframe, I have added data to an element, something like this:
HTML
<div id="data"></div>
Script
$('#data')
.data('test1', 'this is test data 1')
.data('test2', ['John', 'Smith'])
.data('test3', {
alert1: function() {
$('#data').append('test3: successful<br>');
}
})
Now once this page is in an iframe, I know I can access the element as follows:
$('#frame').contents().find('#data');
But when I try to get the data from that element, it's always undefined.
$('#frame').contents().find('#data').data('test1'); // shows up as undefined
I know jQuery stores data()
internally in a cache
object, but I don't know how to access it from outside that document. I set up this demo to display my problem. Click the "Get Frame Data" button to see the results.
I would appreciate any input :)