Skip to content

Instantly share code, notes, and snippets.

@yousuf-hossain-shanto
Created February 6, 2019 04:54
Show Gist options
  • Select an option

  • Save yousuf-hossain-shanto/6098f3e5d51eeed6b180900385bb1ebc to your computer and use it in GitHub Desktop.

Select an option

Save yousuf-hossain-shanto/6098f3e5d51eeed6b180900385bb1ebc to your computer and use it in GitHub Desktop.
Dynamic data attribute grabber (Using Jquery)
var datas = [];
[].forEach.call(this.attributes, function(attr) {
if (/^data-/.test(attr.name)) {
var camelCaseName = attr.name.substr(5).replace(/-(.)/g, function ($0, $1) {
return $1.toUpperCase();
});
datas.push({
name: camelCaseName,
value: attr.value
});
}
});
datas.forEach(function (data) {
$('#' + data.name).val(data.value);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment