Created
February 6, 2019 04:54
-
-
Save yousuf-hossain-shanto/6098f3e5d51eeed6b180900385bb1ebc to your computer and use it in GitHub Desktop.
Dynamic data attribute grabber (Using Jquery)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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