Search code examples
javascriptdombrowserhaxe

Haxe DOMStringMap values not accessible


I'm trying to access the 'data-*' attributes on an element in the browser in Haxe.

var element = document.getElementById('#someId');
var dataLabel = 'label'; //'data-label'
element.dataset[dataLabel] = 5;

That code (which works in plain javascript) generates two compilation errors in HaxeDevelop.

  1. "String should be Int"

  2. "For function argument 'data'"

How can I access element datasets in Haxe? Is there a known proper way to do it?


Solution

  • I ended up using the Element#getAttribute and Element#setAttribute methods to accomplish the same functionality.

    var element = document.getElementById('#someId')
    var dataLabel = 'label'; //'data-label'
    element.setAttribute('data-' + dataLabel, 5);