jquery - Return two data attributes from same div -
how homecoming 2 info attributes of same div? in code below returning the value of data-color div. want homecoming data-background attribute same div can utilize in part 'css: background-color: [data-background value here]';
how in code below?
var colors = $("div").map(function() { homecoming $(this).data("color"); }); var backgrounds = $("div").map(function() { homecoming $(this).data("background"); }); var $ul = $("ul#slideimages"), $swatches = $(".swatches"); $.each(colors, function(i, color) { var $li = $("<li/>", { class: color }); $ul.append(new array(7).join($li.get(0).outerhtml)); $swatches.append($("<swatch/>", { text: color, css: { "background-color": backgrounds }, on: { click: function() { $('ul#slideimages li.' + $(this).text()).prependto('ul#slideimages'); } } })) });
so, these answers don't seem working seek , alter , simplify problem:
i have 2 loops , want loop through loop1 , insert it's data-attribute value loop2. using below how this?
class="snippet-code-js lang-js prettyprint-override">$(".groupa[data-background]").each(function(i){ var backgrounddata = $(this).data('background'); }) $(".groupb").each(function(i){ var insertedbackground = $(this).attr('style'); })
have single function returns map of objects both color
, background
properties, , iterate on collection instead:
var attribs = $("div").map(function () { homecoming { color: $(this).data("color"), background: $(this).data("background") }; }); var $ul = $("ul#slideimages"), $swatches = $(".swatches"); $.each(attribs, function (i, attrib) { var $li = $("<li/>", { class: attrib.color }); $ul.append(new array(7).join($li.get(0).outerhtml)); $swatches.append($("<swatch/>", { text: attrib.color, css: { "background-color": attrib.background }, on: { click: function () { $('ul#slideimages li.' + $(this).text()).prependto('ul#slideimages'); } } })) });
jquery
No comments:
Post a Comment