Friday, February 23, 2024
 Popular · Latest · Hot · Upcoming
-4
rated 0 times [  0] [ 4]  / answers: 1 / hits: 22756  / 12 Years ago, tue, august 14, 2012, 12:00:00

Is there a way to get all 3 data values from this element?



 <div id=viewport 
data-requires='js/base/paths'
data-requires='js/base/dialog'
data-requires='js/base/notifier'>


This would be really useful for a project that I am starting. With this I could load required js modules and link them to the dom. I know it might sound strange, but I'm trying something new here.


More From » html

 Answers
18

You could put them all in one if you separated them by something then split them up and put them in an Array.



var arrayData = document.getElementById('viewport').getAttribute('data-requries');
var arr = arrayData.split(',');

for (i = 0; i < arr.length; i++) {
console.log(arr[i]);
}



http://jsfiddle.net/S7D2D/1/


[#83631] Tuesday, August 14, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
maxinec

Total Points: 117
Total Questions: 116
Total Answers: 116

Location: Bangladesh
Member since Sat, Jan 23, 2021
3 Years ago
maxinec questions
;