JS/jQuery: Get depth of element?
Supposing you don't want to include body and html tag in the parents to count use:
$("#element").parents("*").not("body,html").size()
Online demo here: http://jsfiddle.net/zaJff/
An additional note. If you want to get the depth relative to a certain context you can do:
var depth = $("#my-element","#ContextContainerID").parents("ul").length;
Above, I'm searching for how many UL's are within the container #ContextContainerID
How about:
$('#my-element').parents().length