MCSD MCSD - 3 months ago 46
jQuery Question

Get ID attribute from Kendo dropdownList change event

I am using the kendo dropdownlisthelper, which has a change event, see below

@(Html.Kendo().DropDownListFor(m => m)
.Name(Model.Name)
.Text(Model.PlaceHolder)
.BindTo(Model.ListItems)
.DataTextField("Text")
.DataValueField("Value")
.Enable(Model.Enabled)
.Events(e =>
{
e.Change("change");
})
.HtmlAttributes(new {@id= Model.ID.ToString() })


The function that handles the change event:

function change(e) {
var dataItem = this.dataItem(e.item);
console.log("selected values (" + dataItem.Text + " : " + dataItem.Value + ")");
}


SO this displays the selected value in the console.

The Question:
I'm struggling to work this out, but how do i display the Name and ID of the parent element that made the call to the change event(in this case the drop-down list).

So basically i want to display these values:
- Name attribute of the dropdown list
- Id attribute of the dropdown list

Cheers!

Answer

You can use this approach to get Id of element on which event have occured

function change(e) {
    var elementId = e.sender.element[0].id
}