/ Published in: jQuery

This trick is very useful when you're using UL list to make a menu. What it does is, when you click on the LI area (outside of the link), it will search for the url in the anchor tag and execute the link:
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<!-- HTML --> <ul> <li><a href="home">home</a></li> <li><a href="home">about</a></li> <li><a href="home">contact</a></li> </ul> //JavaScript <script type="text/javascript"> $(document).ready(function(){ $("ul li").click(function(){ //get the url from href attribute and launch the url window.location=$(this).find("a").attr("href"); return false; }); }); </script>
URL: http://www.queness.com/post/126/useful-and-handy-jquery-tips-and-tricks
Comments
