In vanilla-JS, assuming spanEl
is a reference to the DOM node
spanEl.dataset['complexKey'] dataset.complexKey
will work using the camelCasecamelCase
notation (see http://jsbin.com/oduguw/3/edit) when your data attribute contains hypens (-
) and also
spanEl.getAttribute('data-complex-key')
will work fine as you already noticed. As a side note, in jQuery you can access to that data
attribute with
$(spanEl).data("complex-key")