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

Ange Tuteur
Forumaster

Male Posts : 13021
Reputation : 2683
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 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});
   });
});

SSYT
Forumember

Male Posts : 37
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 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

Ange Tuteur
Forumaster

Male Posts : 13021
Reputation : 2683
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