Forum Moderators: open

Message Too Old, No Replies

Change position of div based on z-index

         

ocon

11:15 pm on Aug 9, 2011 (gmt 0)

10+ Year Member Top Contributors Of The Month



I am trying to change the position of a <div> tag on my site using CSS (or by what ever means that works). Unfortunately, this div does not have an id tag, and while it does have a specified class, it is not the only div with this class. Also, it us unknown if it is always displayed in a consistent order with other divs on the page (meaning it may or may not always be, say, the 5th div).

What I do know is that this div, and one other nestled div, has a z-index of 10 specified in the inline, javascript generated, style. Further, this parent div with the z-index of 10 also has the specified class whereas the child div does not.

Can I somehow use javascript to move this div down a few pixels? The site requires javascript, so I am comfortable using javascript as my solution.

lostdreamer

7:06 am on Aug 10, 2011 (gmt 0)

10+ Year Member



If you have jquery allready in the website, it's kind of easy:

<script>
$("div.THE_CLASS").each(function() {
// Loop through all DIV's with this class
var index_current = parseInt($(this).css("zIndex"), 10);
// Check if the z-index = 10
if(index_current == 10) {
// Move it down
$(this).css("margin-top", "10");
}
});
</script>



Regards,
LostDreamer

ocon

9:03 am on Aug 10, 2011 (gmt 0)

10+ Year Member Top Contributors Of The Month



With the exception of adding a unit to the margin-top, that works perfectly! Thank you!