Javascript - variable for method name?

pbarney

How can you reference a javascript object indirectly?

Suppose:

<div id="foo" data-munchy="bar" data-crunchy="baz">FooBar</div>

<script>
document.getElementById("foo").onclick = function() {
    tempVariable = 'munchy';
    console.log(this.dataset.tempVariable);
}
</script>

How can I access this.dataset.{someVariable}? In this case, this.dataset.tempVariable

Is it only possible using eval or window?

Kevin Boucher

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related