javascript - loading external file using jquery and then making reference to it -
i have js file loads content (external html file) dom , alerts content loaded
boo.html
<div id="tyler"> tyler </div>
play.js
$('#result').load('../html/boo.html'); var mike = $('#tyler').text(); alert(mike);
file.html
<html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>a</title> </head> <body> <div id="result"></div> <script type="text/javascript" src="play.js"> </body> </html>
for strange reason when alert(mike)
blank. cant append div id , later reference new div injected?
.load()
asynchronous. goes off , thing , code keeps executing in-line. if check content immediately, won't there yet. takes while server respond, send html , insert dom.
you need use callback this. callback event fired when asynchronous event complete.
$('#result').load('../html/boo.html',function() { alert("moo, callback") });
Comments
Post a Comment