I am having file - index.html, that has embed script.js.
Script.js - is rendering html <a href="url.html" id="url">
tag.
I want to insert in index.html this code, that shows HREF value, that is rendered by script.js:
var d = document.getElementById( 'url' );
alert(d.href);
But this script is working only on tags, that are written index.html.
How to get the script work?
index.html
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript">
var d = document.getElementById( 'url' );
alert(d.href);
</script>
script.js:
document.write("<iframe src=iframe.html></iframe>");
iframe.html:
<a href=url.html id=url>Test URL</a>
--- EDITED ---
My friend came up with this code:
<script type="text/javascript">
$(document).ready(function() {
var href = $("iframe").contents().find("a").attr('href');
alert(href);
});
</script>
But alert() is showing - "undefined"