[dx] Posted May 8, 2012 Share Posted May 8, 2012 Hi, I'm breaking my head few days. I've read whole jQuery page but no help. I have many divs with same class. If I do console.log('.myClass').length); in my case I get 14 elements, and if I try $('.otherClass').each(function(index) { $('.myClass:eq('+index+')').height();}); I get height only for index 0, every other index returns value 0. otherClass is also 14, same as myClass. Also, all my divs have display none propery, except first div with index 0 is display block. It's something like tab sistem. So can it be problem? Regards 1 Link to comment Share on other sites More sharing options...
[dx] Posted May 8, 2012 Author Share Posted May 8, 2012 I've just tried add display: block to index 1 and it shows correct height. But all my divs are loaded in background to source code but with display none. How can I get height for every div? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 8, 2012 Share Posted May 8, 2012 If it set to display none, it has no height. The script is working correctly. If you want it to have a height then don't set the display to none, one option may be to move it off the screen so that it renders where the user can't see it. Link to comment Share on other sites More sharing options...
[dx] Posted May 8, 2012 Author Share Posted May 8, 2012 Thanks, it helped. I solved it by getting data (heights) first, then .hide() all elements which needs to be hidden. Link to comment Share on other sites More sharing options...
dsonesuk Posted May 8, 2012 Share Posted May 8, 2012 $(document).ready(function(){$(".myclass").each(function(){alert($(this).height());});}); works fine even if elements are using display: none; Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now