Watch for Creation of Specific Element (by id) with JQuery?
I am going to be loading a swf into a div tag when the user initiates some action. The div tag's id is container
, the embedded swf's tag id will be swf_content
. I wa开发者_如何学Cnt to be able to set a variable to that swf_content
tag when it is loaded. So something like:
$("#swf_content").ready(function() {
SWF = $("#swf_content").get(0);
})
What is the best way to do this, assuming it won't be loaded until some arbitrary user action?
The simplest way is to use SWFObject, see dynamic embedding section.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>SWFObject dynamic embed - step 3</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
swfobject.embedSWF("myContent.swf", "myContent", "300", "120", "9.0.0");
</script>
</head>
<body>
<div id="myContent">
<p>Alternative content</p>
</div>
</body>
</html>
精彩评论