I am trying to apply a CSS class based on the combined height of the 2nd and 3rd child elements. For example, if the height of the 2nd child plus the height of the 3rd child equals a certain value, I want to add a specific class.
Here is my JavaScript code to perform this calculation -
$(function() {
var fl = $('ul img:nth-child(3n+3)').height();
var fr = $('ul img:nth-child(3n+4)').height();
var result = fl + fr;
if (result == 1092) {
$('ul img:nth-child(3n+3)').addClass('style1a');
$('ul img:nth-child(3n+4)').addClass('style1b');
}
else if (result == 2460) {
$('ul img:nth-child(3n+3)').addClass('style2a');
$('ul img:nth-child(3n+4)').addClass('style2b');
}
else if (result == 1776) {
$('ul img:nth-child(3n+3)').addClass('style3a');
$('ul img:nth-child(3n+4)').addClass('style3b');
}
});
The current script works by calculating the height of the first iteration of 3n+3 and 3n+4, then applies the style to all instances of 3n+3.
However, I need to modify the JavaScript to calculate the height of every iteration of 3n+3 and 3n+4, rather than just the initial one, and then apply the CSS style accordingly.
If the sum of li(3)+li(4) equals a certain value, add a style. If the sum of li(6)+li(7) equals another value, add a different style.
Thank you in advance for any assistance!