How can you do this with jQuery, in an elegant way?
Apply
z
attribute (e.g.: red background) to every children of a divparent
while their position is above a given top-offsety
.
I've tried in different ways, but I'm not happy with any of them...
I know there must be a short and elegant way to do it...
Since you're saying you've tried a few ways, and you're just looking for something more elegant, I'll assume you have the offset part worked out, and I'll just go with
offset
myself. Modify that part as needed. For elegance, you could create a custom selector checking top offset:You could then query it as such:
Of course this could just as well have been expressed as
or, as pointed out in comments
Are the childrens dynamically placed with top-offset or do they all have a common css-class?
Something like this should get the job done:
The selector
'#parent > *'
will select all immediate children (not all descendants) of the element with idparent
. I assume that's what you're looking for, since you said "apply... to every children of a divparent
."Demo: http://jsfiddle.net/mattball/87QFU/1/