<div style="width:50px; height: 50px; overflow:hidden;" id="container">
Длиииииииииииииииинный текст
</div>
<p><a href="#" onclick="return isThereARoomEnough('container');">is there a room enough?</a></p>
<div style="width:50px; height: 50px; overflow:hidden;" id="container2">
Крткй текст
</div>
<p><a href="#" onclick="return isThereARoomEnough('container2');">is there a room enough?</a></p>
<script type="text/javascript">
function isThereARoomEnough(id) {
var cont = document.getElementById(id);
var clone = cont.parentNode.insertBefore(cont.cloneNode(true), cont);
clone.style.overflow = "auto";
var result = ((clone.scrollWidth > cont.offsetWidth) || (clone.scrollHeight > cont.offsetHeight));
clone.parentNode.removeChild(clone);
if (result) {
alert("There is not enough space");
} else {
alert("The container is roomy enough")
}
return false;
}
</script>