I do not think that what you are looking for is possible, but if you want to use positioning, you can try the following:
http://fiddle.jshell.net/JRZXF/12/
HTML:
<div style="position:relative"> <div> To test your code, make the smiley sad, then move it to another div. It must be still sad. </div> <br> <div id ="myApplet"> <applet width="200" height="200" codebase="http://mainline.brynmawr.edu/Courses/cs110/spring2002/Applets/Smiley/" code="Smiley.class" name="Smiley"> </applet> </div> <div id="div1"></div> <br> <div id="div2"></div> <br> <div> <button id="button1">toDiv1</button> <button id="button2">toDiv2</button> </div> β</div>ββββββββββββββ
JavaScript:
function toDiv1() { $('#div1,#div2').empty(); var el = $('#myApplet'), div = $('#div1'), clone_div = $('<div>'); var width = 200, height = 200; clone_div.css({width:width,height:height}); div.append(clone_div); el.css({ position:'absolute'}); el.css({ left:clone_div.offset().left, top:clone_div.offset().top }); } function toDiv2() { $('#div1,#div2').empty(); var el = $('#myApplet'), div = $('#div2'), clone_div = $('<div>'); var width = 200, height = 200; clone_div.css({width:width,height:height}); div.append(clone_div); el.css({ position:'absolute'}); el.css({ left:clone_div.offset().left, top:clone_div.offset().top }); } $('#button1').click(toDiv1); $('#button2').click(toDiv2);β
Of course, this code can be improved and done better. For this example, you need all nested divs to have a relative position. I also gave the width and height 200, but you can make it dynamic, something like:
var width = el.width()
or
var width = el.children('applet').attr('width');
cuzzea
source share