Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags:

Sponsored Links


How do I know the width of an element through javascript?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 06-04-2009
Member
 
Join Date: Jan 2009
Posts: 52
How do I know the width of an element through javascript?

Sponsored Links
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);

Reply With Quote
  #2  
Old 06-04-2009
Kirtikumar's Avatar
Member
 
Join Date: Dec 2008
Posts: 322
Re: How do I know the width of an element through javascript?

you can try with q.clientWidth
Reply With Quote
  #3  
Old 06-04-2009
Member
 
Join Date: Jan 2009
Posts: 52
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
Reply With Quote
  #4  
Old 06-04-2009
opaper's Avatar
Member
 
Join Date: May 2008
Posts: 2,371
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>
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How do I know the width of an element through javascript?"
Thread Thread Starter Forum Replies Last Post
Unable to modify the parent container element before the child element is closed Flicker Software Development 5 18-06-2011 07:39 AM
javascript get element by class GlassFish Software Development 5 06-03-2010 08:05 PM
How to set the value of a form element using Javascript? shivendra Software Development 4 07-02-2010 04:04 AM
Code to scroll to javascript element. sizzla Software Development 2 04-07-2009 10:13 PM
JavaScript - How to create Element Xylina Software Development 3 04-06-2009 05:06 PM


All times are GMT +5.5. The time now is 01:51 AM.