How to add onclick values to a list in Jquery

This bit of jquery will add an onclick value to list items based on the link within the list item.

The idea is that the whole lists items become links rather than just the link text. Its ideal if you want to colour the background of a list item and have it clickable.

<script type="text/javascript">
$(document).ready(function(){
$("li").each(function(){
var url = "location.href='"+$("a", this).attr("href")+"'";
$(this).attr('onclick', url);
});
$("li").each(function(){
var url = "location.href='"+$("a", this).attr("href")+"'";
$(this).attr('onclick', url);
});
});
</script>

The only downside to this method is if you have a list within a list such as a nested Drupal menu.