How to sort page elements by z-index while debugging?
I'm debugging a JavaScript method on an ASP.NET 3.5 web site using jQuery in Visual Studio 2008. As a sanity check, I would like to look at a list of the page elements sorted by z-index. What's a good/easy way to do 开发者_如何学Pythonthis? I would prefer an expression that I can input into the Watch window, but I'm open to other suggestions.
EDIT: @polarblau answered my question, but I wanted to post the code that I ended up using here where it's easier to read. Here's what I pasted into the Watch window in Visual Studio:
$.map($('*').sort(function(a, b) { return b.style.zIndex - a.style.zIndex; }), function(e) { return '[' + e.id + '] = [' + e.style.zIndex + ']'; }).join(', ')
Would something like this work? —
var sortByZIndex = function(a, b) {
return a.style.zIndex - b.style.zIndex;
}
var sorted = $('div').sort(sortByZIndex);
alert("Sorted: " + $.map(sorted, function(e){ return e.id; }).join(', '));
精彩评论