How do I know the width of an element through javascript?
There is a div defined field sizes. It is a text (in each case is different). A maximum size (size) of the text.
Question: how to define the width of the text to dynamically reduce the size if it got the edges? If the current tag div invest another, but does not assign importance to the method
Code:
Quote:
var q = document.getElementById ( 'qwerty');
alert (q.currentStyle.width);
Re: How do I know the width of an element through javascript?
you can try with q.clientWidth
Re: How do I know the width of an element through javascript?
in IE returns the width of the previous element, if it is determined, or the width of the screen if the width of the previous element is not defined ... when viewing the properties of such a code
Code:
Quote:
function ShowProperties () (
var result;
var objName = "qwerty";
var q = document.getElementById ( "qwerty")
for (var i in q) result + = objName + "." + I + "=" + q [i] + "<br /> \ n";
document.all.item ( "result"). innerHTML = result;
)
I have not noticed any contains that the current width and can be any circuit to know the width of the text
Re: How do I know the width of an element through javascript?
and you do so - and will become evident why
Code:
Quote:
<div id='test' style='border: 1px solid black'> Some text here </ div>
then both
Code:
Quote:
<span id='test' style='border: 1px solid black'> Some text here </ span>
<script>
alert (document.getElementById ( 'test'). offsetWidth)
</ script>