How to get id value in kendo menu

I use the kendo menu in my project. I want to get the id value when I click on the selected item. I used the onSelect event and I can get the selected Text.can element u tell me how to get the id value

+4
source share
2 answers

You can set the identifier in the UL / LI structure from which you initialize it (check Robotsushi's answer). However, if you want to initialize the menu dynamically, you can use something like this - http://jsfiddle.net/MMRCf/8/

+4
source

You can use HTML5 data attributes to accomplish this.

HTML

<div id="example" class="k-content"> <ul id="menu"> <li> First Item <ul> <li data-id="12345">Sub Item 1 with ID</li> <li>Sub Item 2</li> <li>Sub Item 3</li> <li>Sub Item 4</li> </ul> </li> <li> Second Item <ul> <li>Sub Item 1</li> <li>Sub Item 2</li> <li>Sub Item 3</li> <li>Sub Item 4</li> </ul> </li> <li> Third Item <ul> <li>Sub Item 1</li> <li>Sub Item 2</li> <li>Sub Item 3</li> <li>Sub Item 4</li> </ul> </li> <li> Fourth Item <ul> <li>Sub Item 1</li> <li>Sub Item 2</li> <li>Sub Item 3</li> <li>Sub Item 4</li> </ul> </li> <li> Fifth Item <ul> <li>Sub Item 1</li> <li>Sub Item 2</li> <li>Sub Item 3</li> <li>Sub Item 4</li> </ul> </li> </ul> </div> 

And Javascript:

  <script> $(document).ready(function() { function onSelect(e) { var id = $(e.item).attr('data-id'); } $("#menu").kendoMenu({ select: onSelect }); }); </script> 
+6
source

All Articles