You can detect whether text will fit before you display the element. So you can use this function which doesn't require the element to be on screen.
function textWidth(text, fontProp) {
var tag = document.createElement('div')
tag.style.position = 'absolute'
tag.style.left = '-99in'
tag.style.whiteSpace = 'nowrap'
tag.style.font = fontProp
tag.innerHTML = text
document.body.appendChild(tag)
var result = tag.clientWidth
document.body.removeChild(tag)
return result;
}
Usage:
if (textWidth('Text', 'bold 13px Verdana') > elementWidth) {
...
}