Dynamic width of DIV (offsetWidth issue).
- by Tom
Hi all,
I face issue with retrieving (via javascript) width of the div which content is changed (just before reading the widht via offsetWidth) in dynamic way (via changing innerHTML or using createTextNode).
Here is some sample code:
var con = document.getElementById('avContent'); //content div within page
var temp = document.createElement('div');<br />
var text1 = document.createTextNode('CCCCC');<br />
temp.appendChild(text1);<br />
con.appendChild(temp);<br />
var length1 = temp.offsetWidth;<br />
var text2 = document.createTextNode('CCCCC33333333vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv');<br />
temp.removeChild(text1);<br />
temp.appendChild(text2);<br />
con.removeChild(temp);<br />
con.appendChild(temp);
var length2 = temp.offsetWidth;<br />
The length1 and length2 do have the same width.. (the same result I get while using innerHTML instead of createTextNode).
Looks like it's the same issue like described in following discussion:
http://www.webdeveloper.com/forum/showthread.php?t=187716
Does anybody have answer (work around)?
Thanks much for help in advance.