2

This is the anchor that MVC 2 is creating:

<a class="syncLink" data-resultstarget="OmsToAdminPzInfoSyncResult" 
     href="/Sync/OmsToAdminPzInfoAjax" 
     onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: &#39;OmsToAdminPzInfoSyncResult&#39; });">
Pz Info</a>

And here's some jQuery. The first alert shows what it should, but the second shows undefied. I'm using jQuery 1.4.1

    $("a.syncLink").click(function () {
        alert($(this).attr("data-resultstarget"));
        alert($(this).data("resultstarget"));
    });

I know I asked this question before, but I don't have any camel casing here, so I'm not sure what the issue is.

Community
  • 1
  • 1
Adam Rackis
  • 82,527
  • 56
  • 270
  • 393
  • Works for me in [jQuery 1.7](http://jsfiddle.net/Y9S4T/) but not [in jQuery 1.3.2](http://jsfiddle.net/Y9S4T/1/) – Phrogz Nov 22 '11 at 19:00

2 Answers2

8

This feature was added in jQuery 1.4.3.
You need to upgrade jQuery.

In older versions, you'll need to use .attr("data-resultstarget")

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • 4
    @PaulD.Waite: No; it says 1.4.3. http://api.jquery.com/data/ `As of jQuery 1.4.3 HTML 5 data- attributes will be automatically pulled in to jQuery's data object. The treatment of attributes with embedded dashes was changed in jQuery 1.6 to conform to the W3C HTML5 specification.` – SLaks Nov 22 '11 at 19:01
  • Docs say data was added in 1.2 - so that was only for local, in-memory storage—ie not reading from html5 attributes? http://docs.jquery.com/Data – Adam Rackis Nov 22 '11 at 19:02
  • 1
    Ok - got it. Data was extended in 1.4.3 to support html5 data attributes. Thank you for the quick answer @SLaks. – Adam Rackis Nov 22 '11 at 19:03
  • 1
    I went and reviewed the source code for 1.4.1 just to check, and there's definitely no data-attribute logic behind-the-scenes. – zzzzBov Nov 22 '11 at 19:06
1

Upgrade your jQuery library. This feature was added in the later version.

ShankarSangoli
  • 69,612
  • 13
  • 93
  • 124