views:

41

answers:

1

HTML

<div id='accordion'>
     <h5>Header 1</h5>
     <ul>
        <li>section 1 content visible</li>
        <li>
             <div id=showhide>
                   <textarea id=usertext>
                   user entered text here,scalable
                   </textarea>
             </div>
        </li>
     </ul>
     <h5>Header 2</h5>
     <ul>
        <li>section 2 content 1</li>
        <li>section 2 content X</li>
     </ul>

</div>

#showhide can be either visible or hidden (to save space) How to get dimensions of #usertext regardless of which section of accordion is expanded and whether #showhide is visible or collapsed?

jquery's .width() does not return value for hidden elements. I could potentially set display:block but there are a lot of elements on the page and I send dimensions in async JS post, I cannot coordinate the timing of showing elements and getting its dimensions. I don't want to go to sync since page will freeze for a long time.

Any suggestions?

+1  A: 

Maybe this plugin could help you: http://plugins.jquery.com/project/evenIfHidden

A. M.
This looks promising! But the way it works $('#box').evenIfHidden( function(element) { alert( element.width() ); });How do you return a value?
selytch
It depends on what you want to do with the value. For example, if you want to store it in a variable you replace alert( element.width() ); with varname = element.width().
A. M.
I'm somewhat new to java, so what if I want to do something like`var dim=$('#box').evenIfHidden(function (element) {return {w:element.width(), h:element.height(), t:element.top()}});''Cause now I get $('#box') object in dim...
selytch
That's javascript, not java. I don't think element.top() works in jquery, you have to use element.position(). Then you would write something like $('#box').evenIfHidden( function(element) { position = element.position(); dim = {w:element.width(), h:element.height(), t:position.top}; }); this will put the values you want in the dim variable (I think you also have to declare dim before that).
A. M.