Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Monday, July 5, 2010

jQuery LI onClick Even

This jQuery hint is a great one, often times we us the ul li tags to create navigation, well people get annoyed when they click on the list item and it doesn't navigate to the destination of the link listed.

If you are using jQuery there is a really cool way to make all li's that have a link navigate to that on an onclick event.

Add the following to your $(document).ready(function(){

if( $(this).children("a").index() >= 1 ){
$('li').click(function(){ window.location = $(this).children("a").attr("href"); });
}

Then any li that has a child a will then be an onclick event to follow the link.

Really cool!!

No comments:

Post a Comment