0

I am trying to attach change event handler to the instance of kendoNumercTextBox. I am able to get the instance of kendoNumercTextBox control using its ID, however Im not able to get the instance using class name

here is the code http://dojo.telerik.com/emIWa/11

NOTE

  • I DO NOT want to attach event handler at the time of instantiating the control. I want to get the existing instance and then attach the event handler.
  • Also i am actually using Kendo ASP.NET MVC, however dojo doesn't allow me to write cshtml so i am using kendo UI for the demo purpose above. But i think end result would be same.
    The NumericTextBox is created like below in cshtml

     @(Html.Kendo().NumericTextBoxFor(x =>x.numerictextbox).HtmlAttributes(new {@class = "MyClass"}))
    
LP13
  • 30,567
  • 53
  • 217
  • 400

1 Answers1

1

You need to use a more specific jQuery selector. This for example will get the correct element which is the one with the data-role attribute:

var numerictextboxByClassName = $(".MyClass [data-role]")

If you use the developer tools in your browser to inspect the text box, you'll see that 'MyClass' is on several elements that comprise the widget, hence the need to be more specific. It is also worth noting that the handler will only attach to the first instance found using the selector so this method cannot be used to attach a handler to several such controls at the same time.

NigelK
  • 8,255
  • 2
  • 30
  • 28
  • Thanks That worked. Is there any way to check if control that fired the change event certain class name? the way i am doing it in change event handler as 'function(e) { $(e.sender.elements[0]).hasClass('SomeClass') }' – LP13 Apr 26 '16 at 04:16
  • `function(e) { $(e.sender.elements[0]).hasClass('SomeClass') }` – LP13 Apr 26 '16 at 04:23