I was looking at this stackoverflow question
how to get data attributes of dynamically generated element
which led me to this fiddle – http://jsfiddle.net/Mk2zy/
But for some reason – it wasn’t working on my code. Then I checked the Jquery version – and the fiddle uses 1.5.2 – So on the fiddle if I update the jquery version to anything above 1.5.2 – it doesn’t return the value anymore – it returns undefined.
Am I missing something simple here
Thanks for looking in
Use
data-contentid(in the jQuery script only, see below), all lowercase, as defined by the W3 specification. The jQuery developers may have overlooked that requirement and resolved it for later versions.The above statement translates to: If there are uppercase letters in
data-*attributes, they are automatically changed to lowercase, in the HTML, not scripts. This is why$('data-contentId')is undefined, becausedata-contentIdin the HTML was changed todata-contentid.