Giuseppe De Luca Giuseppe De Luca - 1 year ago 108
jQuery Question

Get data-attributes values and append() them in a string

I want to retrieve data-attributes values and append them into a string.

So far, I've got the retrieving part to work but as jquery & programming are not really my thing, all I could manage is to show the result in an alert.

<a data-1="312UaZo2kvL" data-2="41qmDp9xesL" data-3="41pJL%2BWA-eL">Link</a>

var imaglist = "";
$.each($('a').data(), function(i, v) {

var temp = '<img src ="' + v + '.jpg"></li>';
var strToInsertInimaglist = '<li data-thumb ="' + v + '._SL75_.jpg">' + temp;


I can't figure out how to insert or append the results in the imaglist variable that I can use later (I want to dynamically update a slider actually)

Would somebody be so kind as to take a look and tell me how I can do that please ?


Answer Source

imaglist is outside the each so it should be scoped right. Did you try appending to it? imaglist += strToInsertInimaglist; ?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download