The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

.each function, does not work properly

Go down

Solved .each function, does not work properly

Post by Ahmed.K on June 21st 2014, 7:23 pm

I try to add a dynamic css (max-height) for each element.
But i find one max-height for all the elements. any ideas?

Code:
$(document).ready(function(){
$('.cbreplay').each(function() {
var height = $('.cbrepl-left').height();
var maxheight = height - 28;
$('.cbnota-container').css({'max-height':maxheight});
});
});

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

Solved Re: .each function, does not work properly

Post by Ange Tuteur on June 21st 2014, 9:09 pm

Hello Ahmed.K,

You must use the this keyword to refer to the iterated element.

Ex :

I'm assuming .cbrepl-left is a child of .cbreplay, so use $(this).find()
Code:
var height = $(this).find('.cbrepl-left').height();
avatar
Ange Tuteur
Forumaster

Male Posts : 13194
Reputation : 2908
Language : EN10, FR5, JA5
Location : Macungie, PA

https://github.com/SethClydesdale

Back to top Go down

Solved Re: .each function, does not work properly

Post by Apollo 2.0 on June 22nd 2014, 8:50 am

Try code new Smile
Code:
$(document).ready(function(){
   $('.cbreplay').each(function(a, b) {
      var height = $('.cbrepl-left', b).height();
      var maxheight = height - 28;
      $('.cbnota-container', b).css({'max-height':maxheight});
   });
});
avatar
Apollo 2.0
Forumember

Male Posts : 65
Reputation : 12
Language : RO-10, EN-3, FR-1
Location : Romania

http://help.forumgratuit.ro/forum

Back to top Go down

Solved Re: .each function, does not work properly

Post by Ahmed.K on June 24th 2014, 11:38 pm

Ah, thanks, It works fine now.

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

Solved Re: .each function, does not work properly

Post by Ange Tuteur on June 25th 2014, 12:00 am

Topic archived

Have a good day. Smile
avatar
Ange Tuteur
Forumaster

Male Posts : 13194
Reputation : 2908
Language : EN10, FR5, JA5
Location : Macungie, PA

https://github.com/SethClydesdale

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum