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

View previous topic View next topic Go down

Solved .each function, does not work properly

Post by Ahmed.K on Sat 21 Jun 2014 - 13:23

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 Sat 21 Jun 2014 - 15:09

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();

Ange Tuteur
Forumaster

Male Posts : 13038
Reputation : 2718
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: .each function, does not work properly

Post by SSYT on Sun 22 Jun 2014 - 2:50

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});
   });
});

SSYT
Forumember

Male Posts : 43
Reputation : 2
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 Tue 24 Jun 2014 - 17:38

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 Tue 24 Jun 2014 - 18:00

Topic archived

Have a good day. Smile

Ange Tuteur
Forumaster

Male Posts : 13038
Reputation : 2718
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

View previous topic View next topic Back to top


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