As the title refers to this function doesn't seem to work with DOM elements appended after the document.ready function.
I am appending a new .window
element, but this function still only handles the .window
elements created when loading the script.
How do I make it react on appended elements also?
$(function() {
// Change this selector to find whatever your 'boxes' are
var windows = $("div.window");
// Set up click handlers for each box
windows.mousedown(function() {
var tz = parseInt($('#toolbar').css( "z-index" ), 10 );
$('#toolbar').css( "z-index", tz +1 )
var el = $(this), // The box that was clicked
max = 0;
// Find the highest z-index
windows.each(function() {
// Find the current z-index value
var z = parseInt( $( this ).css( "z-index" ), 10 );
// Keep either the current max, or the current z-index, whichever is higher
max = Math.max( max, z );
});
// Set the box that was clicked to the highest z-index plus one
el.css("z-index", max + 1 );
orderWindows(el);
});
});