I tried it but it didn’t get the expected outcome.
Please never mind though, the problem probably comes from the content management system with all its JavaScript-induced-dynamicity and elements with CSS display: none in the same wrapper on which its children I work…
Opp, sorry,
It does work as expected !
I just checked the last element and indeed its CSS margin-top property and value have strike-through on them:
But, a strange problem is the reduction of some margin inside the element itself (between two children of the element itself, as evident below in Hebrew and English).
It’s why before being able to use code like firstElementChild or nextElementSibling under the hood Jquery would use code like this
// nextSibling
function next( elem ) {
do {
elem = elem.nextSibling;
} while ( elem && elem.nodeType != 1 ); // while not an element
return elem;
}
// firstChild
function first( elem ) {
elem = elem.firstChild;
return (elem && elem.nodeType != 1) // if not an element
? next ( elem )
: elem;
}
Assuming that .x is going to be either the first or last elements in that group. If other stuff is mixed in with those elements then it would not work.
Also bearing in mind that due to collapsing margins the above will have no effect if siblings have their own top and bottom margins.