My previous answer can only take you as far as FINDING the height/width, but it does actually not CHANGE the height/width of the div itself.
So after the width/height is found using my previous answer, here is how to change the width/height of the div in question.
Lets say your div ID is "draggable" and your p ID is "text". When you are done editing your text you can update width and height by calling a function (defined below).
resize("draggable", "text");
You can imitate CSS styles in javascript like so:
function resize(id1, id2)
{
var divName = document.getElementById(id1);
divName.style.position = absolute;
divName.style.width = getWidth(id2)+"px"; // remember the +"px"!!
divName.style.height = getHeight(id2)+"px";
}
This will set the height and width of your div to be equal to the height and width of your text area. By doing like so you can change the height and width of any giving ID according to any other in your project. getWidth() and getHeight() is a reference to my previous post.
A combination of my 2 answers should be able to accomplish what you are looking for. I apologize for not giving a proper answer the first time around, but I'm still new both to programming and to this site. I'll try to do better in future. I hope that this time around you'll succeed in both getting and setting the sizes of your div.
--EDIT--
code from my previous post:
function getHeight(id)
{
if(document.getElementById(id) == null) //simply a guard that returns 0 if a wrong ID is stated. In reality the return statement is enough.
return Number(0);
else
return document.getElementById(id).offsetHeight; // Change to .offsetWidth to gain width :)
}
function getWidth(id)
{
return document.getElementById(id).offsetWidth;
}
-- END EDIT--
- Molle