This is a migrated thread and some comments may be shown as answers.

How to change item text

1 Answer 89 Views
Toolbar
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 10 Oct 2017, 01:43 PM

Hi,

If I change the text of a button it removes span and other classes as well.

This is my code but doesn't work.

@(Html.Kendo().Menu()

                            .Name("HeaderMenu")
                            .Items(items =>
                            {
                                items.Add().Text("Home").Action("Index", "Home").SpriteCssClasses("fa fa-home");
                                items.Add().Text("About").Action("About", "Home").SpriteCssClasses("fa fa-info");
                                items.Add().Text("Contact").Action("Contact", "Home").SpriteCssClasses("fa fa-mobile-phone");
                                items.Add().Text("User").HtmlAttributes(new { id = "userloggedin" }).SpriteCssClasses("fa fa-user").Items(children => {
                                    children.Add().Text("Sign out").SpriteCssClasses("fa fa-sign-out").HtmlAttributes(new { id = "signout" }).Enabled(false);
                                });
                            }))

 

<script type="text/javascript">
    function onButtonClick(e) {
            var html = $("#userloggedin").children(".k-link").html();
            console.log(html);
            $("#userloggedin").children(".k-link").text("It is me!");

            html = $("#userloggedin").children(".k-link").html();
            console.log(html);

    }

</script>

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 12 Oct 2017, 08:29 AM
Hello Paul,

I would suggest to use the built-in methods of the Kendo UI Menu to achieve the desired result. You can checkout the following API Reference:

  • append() - appends an item to a Menu in the specified referenceItem's sub menu.

  • insertAfter() - inserts an item into a Menu after the specified referenceItem.

  • insertBefore() - inserts an item into a Menu before the specified referenceItem.

  • remove() - removes a specified item(s) from a Menu.

I am also attaching an ASP.NET MVC solution, where I have used the remove() and append() methods to modify the items of the Menu widget on the click of a button.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Toolbar
Asked by
Paul
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or