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

Get HTML attribute value in javascript

2 Answers 832 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 2
Andrew asked on 17 Oct 2012, 04:16 PM
I've declared a NumericTextBox using the MVC helpers, and specified a custom HTML attribute as follows:

@(Html.Kendo().NumericTextBoxFor(a => costRow.FTE)
    .Name(costRow.CostRowId + "_FTE")
    .Step(new decimal(0.5))
    .Events(e => e
        .Change("fteChanged")
        .Spin("fteChanged")
        )
    .HtmlAttributes(new { guid=costRow.CostRowId })
)

Is there any way of getting the value of the 'guid' attribute from the 'fteChanged' function in JavaScript? I've tried $(this).attr('guid') but that doesn't give me anything.

2 Answers, 1 is accepted

Sort by
0
Andrew
Top achievements
Rank 2
answered on 18 Oct 2012, 08:45 AM
I've just discovered that I can use $(this.wrapper.context).attr('guid') - can anybody from Telerik confirm whether this is the best, or indeed a safe, way of doing this?

Thanks.
0
Atanas Korchev
Telerik team
answered on 18 Oct 2012, 10:01 AM
Hello,

 The proper way to get an attribute of an html element via jQuery is to use the attr method:

$("#someid").attr("someattribute").

 In the context of a Kendo widget this is the right code:

var attr = this.element.attr("attrname");

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
NumericTextBox
Asked by
Andrew
Top achievements
Rank 2
Answers by
Andrew
Top achievements
Rank 2
Atanas Korchev
Telerik team
Share this question
or