Get elements ID

5 posts, 0 answers
  1. Damon
    Damon avatar
    7 posts
    Member since:
    Dec 2011

    Posted 09 Dec 2011 Link to this post

    I'd like to know if it is possible to get the elementId during an event?

    Example.  I have a slider control that I'd like to grab the id of the slider and then update the correlating text control.

    e.g.

    Text:  <input id="panelBarColor-bg"  ......
    Slider <input id="panelBarColor" .......

    So on slide I could update the text control with the value of the panelBar.
    The reason I ask is I have a lot of sliders and it would be great to have one handler based on the Class instead of several based on the Id.
    If I can grabbed the sliders id that triggered the event I can parse it to update the text.  I've done this with other standard controls.

    I've looked through the docs, but either I am missing how to do that, I am still not as well versed in Jquery as I need to be (more than likely), or it is not possible right now.

    thanks a mil!
    Damon
  2. T. Tsonev
    Admin
    T. Tsonev avatar
    2770 posts

    Posted 09 Dec 2011 Link to this post

    Hello Damon,

    The event handlers are executed in the context of the invoking component. In other words this is the current slider.

    function sliderOnChange(e) {
        var slider = this;
        var elementId = slider.element.id;
        // ...
    }

    I hope this helps.

    Regards,
    Tsvetomir Tsonev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Damon
    Damon avatar
    7 posts
    Member since:
    Dec 2011

    Posted 09 Dec 2011 Link to this post

    Hey Tsvetomir:

    Thanks for the quick reply.  I tried it but I keep getting UNDEFINED when I look at the elementId.  

    I was able to finally get the id.  Instead of slide.element.id  you have to use slide.element.context.id.
    I hope this helps others. These are GREAT controls.

    Here is my code:

    var slider = $(".balSlider").kendoSlider({
            showButtons: false,
            change: sliderOnChange,
            slide: sliderOnSlide,
            min: -10,
            max: 10,
            smallStep: 2,
            largeStep: 1
        });
     
        function sliderOnChange(e) {
            var slide = this;
            var elementId = slide.element.context.id;
            alert(elementId);
         // ...
         }
          
         function sliderOnSlide(e) {
            var slide = this;
            var elementId = slide.element.context.id;
            alert ('ELEMENT: ' + elementId );
         // ...
         }
  5. kabsila
    kabsila avatar
    1 posts
    Member since:
    Mar 2014

    Posted 25 Jun 2014 in reply to Damon Link to this post

    Thank you, Damon
    This work.
  6. Stephen
    Stephen avatar
    1 posts
    Member since:
    Sep 2014

    Posted 22 May 2015 in reply to Damon Link to this post

    Thanks Damon,

    I have been looking everywhere for this life saver!

     

    Stephen

Back to Top
Kendo UI is VS 2017 Ready