Jump to content
[dx]

jQuery :eq() selector

Recommended Posts

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

  • Like 1

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Thanks, it helped. I solved it by getting data (heights) first, then .hide() all elements which needs to be hidden.

Share this post


Link to post
Share on other sites
$(document).ready(function(){$(".myclass").each(function(){alert($(this).height());});});

works fine even if elements are using display: none;

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×