3

Here is the following HTML:

<div style="visibility: hidden;">
 <span id="myId" data-recipientId="2"></span>
</div>

Here is the jQuery:

var recipientId = $("#myId").data("recipientId");

I noticed that recipientId is always undefined...

balteo
  • 23,602
  • 63
  • 219
  • 412
  • also similar: http://stackoverflow.com/questions/10992984/jquery-data-returns-undefined-attr-returns-integer – trante Feb 05 '14 at 15:53

1 Answers1

7

data attributes are lowercase.

$("#myId").data("recipientid")

It would be more correct to use this:

<div style="visibility: hidden;">
 <span id="myId" data-recipient-id="2"></span>
</div>

and

$("#myId").data("recipientId")

FIDDLE

Kevin B
  • 94,570
  • 16
  • 163
  • 180