Sin Framework sería así (quizá te sirva de guía):
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<script type="text/javascript">
function $(x){return document.getElementById(x);}
function addEvent(obj,fun,type){
if(obj.addEventListener){
obj.addEventListener(type,fun,false);
}else if(obj.attachEvent){
var f=function(){
fun.call(obj,window.event);
}
obj.attachEvent('on'+type,f);
obj[fun.toString()+type]=f;
}else{
obj['on'+type]=fun;
}
}
onload=function(){
var li=document.getElementsByTagName('li');
for(var i=0,l=li.length;i<l;i++){
addEvent(li[i],function(){
var p=this,c=0;
while(p && p.nodeName.toLowerCase()!='ul'){
if(p.nodeName.toLowerCase()=='li'){
c++;
}
p=p.previousSibling;
}
alert(c);
},'click');
}
}
</script>
</head>
<body>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</body>
</html>