How to access custom data attributes in a Switch's data-change function

2 posts, 0 answers
  1. Peter
    Peter avatar
    7 posts
    Member since:
    Feb 2012

    Posted 17 Jan 2013 Link to this post

    I've seen various comments on best practice for doing this, but nothing definitive (that I've found) on the proper way to do this.

    Given this:

    <input data-role="switch" data-change="switchChangedHandler" data-subscriptionId="10" id="switch1"/>
    <input data-role="switch" data-change="switchChangedHandler" data-subscriptionId="9" id="switch2"/>
    <input data-role="switch" data-change="switchChangedHandler" data-subscriptionId="8" id="switch3"/>
    How best to access subscriptionId in the handler function?
    function switchChangedHandler(e) {
         // I've seen this in a forum example but is it really the best way?
        var subscriptionId = e.sender.element.context.dataset.subscriptionId;
         // How to best get it?
    somehow the solution shown doesn't seem like the "Kendo" way.
  2. Alexander Valchev
    Alexander Valchev avatar
    2895 posts

    Posted 21 Jan 2013 Link to this post

    Hello Peter,

    I suggest to use the data method of jQuery. Here is an example:
    var id ="subscriptionid");

    For convenience I created a small example (please watch the console) using this approach in action.
    I hope this will help.

    Alexander Valchev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top