[solved] Adding an onclick to a menu list
Hi everyone,
Just wondered if someone can help or point me in the right direction. I have a menu generated by a cms and I want to add an onclick event.
ie.
current menu:
-
<ul>
<li><a href="/">Home</a></li>
<li><a href="about">About</a></li>
</ul>
want to end up with:
-
<ul>
<li onclick="location.href='/'"><a href="/">Home</a></li>
<li onclick="location.href='about'"><a href="about">About</a></li>
</ul>
ie. I need some code to go through each menu item taking the href value and adding it to the onlclick event.
So far I have the following code but I've become stuck on adding a loop to go through each li element:
-
$(document).ready(function(){
var url = "location.href='"+$("#block-menu-menu-pfse li.leaf a").attr("href")+"'";
$("#block-menu-menu-pfse li.leaf").attr('onclick', url);
});
Many thanks