wrote:
[...]
> <style type="text/css">
> .cycle { position: relative }
> .cycle img { position: absolute; z-index: 1 }
> .cycle img + img { top: 2em; left: 2em; z-index: 0 }
> </style>
> <script type="text/javascript">
> function mouseclick(event) {
> var target = event.target;
> var parent = target.parentNode;
> if (target.tagName == "IMG" && parent.className == "cycle") {
> parent.appendChild(target);
> }
> }
> document.addEventListener("click", mouseclick, false);
> </script>
> ...
> <div class="cycle">
> <img src="image1.png">
> <img src="image2.png">
> </div>
>
> This gives the overlapping visual effect I was after. When I click on
> the top image, it jumps down into the lower position, completely
> obscuring the lower image, but the lower image does NOT move into the
> upper position. I had been expecting that after the appendChild
> operation, with the second child of the div now becoming the first
> child, the third style rule would no longer be applied to it, but
> something about my expectation is clearly incorrect. Anyone have any
> idea what might that be?
You haven't said which browser you're using to look at it in. It works
as you describe in Opera 9.5b and Firefox 3.0b4. If you're using Firefox
< 3.0, then its failure may be explained by <URL:
https://bugzilla.mozilla.org/show_bug.cgi?id=73586>.
You can still do what you want, but it's safest to steer clear of
adjacent sibling selectors, which are relatively recently implemented.
You can either swap the image src to achieve the effect or use class
selectors and swap the className property of the elements, which I
suspect is the more efficient option.