Is it possible to register a html data-attribute as the name of a javascript variable?
What I am talking about is something like this:
<form>
<input data-varName="test1" />
<input data-varName="test2" />
</form>
$('form').find('input').each(function() {
var $(this).attr('data-varName') = $(this).val();
});
The correct syntax to target data
attributes is:
var myVar = $(this).data("varName");
See here for more info:
https://api.jquery.com/data/
EDIT --
This doesn't address the issue of how to set the variable name, but it is the correct method for targeting data attributes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With