How to get the selected menu item text from JavaScript

3 posts, 0 answers
  1. Ian
    Ian avatar
    11 posts
    Member since:
    Aug 2013

    Posted 11 Oct 2013 Link to this post

    I would like to get the text for a selected menu item from JavaScript/jQuery in a clean way. I would rather not use jQuery matching for specific classes if possible, I'm hoping for something like:

    $("#myMenu").getSelectedItemText()

    Alternatively, I guess I could populate a variable during a Select event handler or something. 

    Any suggestions?  Thanks!
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 14 Oct 2013 Link to this post

    Hi Ian,

     You can use the following code to get the selected item's text:

    function onSelect(e) {
          var item = e.item;
          var text = $(e.item).children(".k-link").text();
    }

    A live demo is available here: http://demos.kendoui.com/web/menu/events.html

    Regards,
    Atanas Korchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Ian
    Ian avatar
    11 posts
    Member since:
    Aug 2013

    Posted 14 Oct 2013 Link to this post

    Thanks for the reply. I see how this would work and similarly I could also get the selected text outside of a select handler using ".children(".k-state-selected").text()". I was not sure it was good practice, however,  to use specific classes for this purpose (implementation detail) rather than to use a Kendo API function. I'm guessing there is no such function :)
Back to Top