[SOLVED] JQuery Swap 2 div's z-index

Issue

I tried to swap the z-index of two div elements.

The following code is my attempt to switch the two z-indices:

else if (pen_state == 1) {
                var pen_zindex = $("#pen").css("z-index");
                var curtain_zindex = $("#curtain").css("z-index");
                if (curtain_zindex < pen_zindex) {
                    $("#curtain").css('z-index',pen_zindex);
                    $("#pen").css('z-index',curtain_zindex);
                }
            }

But whatever I do, I can not swap them.

Solution

The code you have seems to work for me when the elements are position:absolute. See this example: http://jsfiddle.net/ChrisMBarr/AZXmU/

Answered By – FiniteLooper

Answer Checked By – Robin (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *