Get HTML attribute value in javascript

3 posts, 0 answers
  1. Andrew
    Andrew avatar
    20 posts
    Member since:
    Jun 2012

    Posted 17 Oct 2012 Link to this post

    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. Andrew
    Andrew avatar
    20 posts
    Member since:
    Jun 2012

    Posted 18 Oct 2012 Link to this post

    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.
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 18 Oct 2012 Link to this post

    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!
Back to Top