Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery onclick event for <li> tags

Tags:

jquery

I have the following menu items generated by a template generator, artisteer:

<ul class="art-vmenu">  <li><a href="#" ><span class="l"></span><span class="r"></span>         <span class="t">Home</span></a></li>     <li><a href="#" ><span class="l"></span><span class="r"></span>         <span class="t">Create User</span></a></li>  <li><a href="#" class="active"><span class="l"></span><span class="r"></span>         <span class="t">List Users</span></a></li>   <li><a href="#"><span class="l"></span><span class="r"></span>         <span class="t">Admin</span></a></li>    </ul> 

I want to capture the onclick event for <li> with a single jQuery function: I've tried this which is incomplete:

$(document).ready(function()  {    $('ul.art-vmenu li').click(function(e)     {      alert(this);    }); }); 

I can go as far as seeing this is a HTMLliElement but cannot figure how to get the menu text or id for it?

How is menu click usually captured with jQuery?

like image 586
afshin Avatar asked Jun 15 '11 22:06

afshin


1 Answers

Here, to get the text of the menu that triggered the event (does not seem to have any id):

 $(document).ready(function()   {     $('ul.art-vmenu li').click(function(e)      {       alert($(this).find("span.t").text());     });  }); 
like image 81
Locksfree Avatar answered Sep 28 '22 09:09

Locksfree