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

Get elements ID

4 Answers 1154 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Damon
Top achievements
Rank 1
Damon asked on 09 Dec 2011, 06:27 AM
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

4 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 09 Dec 2011, 08:35 AM
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!
0
Damon
Top achievements
Rank 1
answered on 09 Dec 2011, 10:58 PM
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 );
     // ...
     }
0
kabsila
Top achievements
Rank 1
answered on 25 Jun 2014, 08:20 AM
Thank you, Damon
This work.
0
Stephen
Top achievements
Rank 2
answered on 22 May 2015, 03:25 PM

Thanks Damon,

I have been looking everywhere for this life saver!

 

Stephen

Tags
General Discussions
Asked by
Damon
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Damon
Top achievements
Rank 1
kabsila
Top achievements
Rank 1
Stephen
Top achievements
Rank 2
Share this question
or