On Jun 30, 10:59 am, Dan <[EMAIL PROTECTED]> wrote: > But when I click, it adds the red text color to all parents too. I > changed the code too print the index number and it appends several > index numbers to the element I click and the parents. > > [...] > > So, how do I get only the top most element index that I clicked on?
I think just adding one line to the handler would do the trick (also add the "ev" argument to the function): $(document).ready(function(){ $("*", document.body).click(function(ev) { var index = $("*", document.body).index(this); $("*:eq(" + index + ")", document.body).css("color", "red"); ev.stopPropagation(); }); });