javascript - append value of data attribute to dom -


i extract values of date-res , data-ref jquery , append it's div.

<div id="grid"> <div class="item blue" date-res="8" date-ref="13" data-groups='["all", "letters", "blue", "square"]'>d</div> <div class="item green" date-res="9" date-ref="10" data-groups='["all", "letters", "blue", "square"]'>e</div> <div class="item green" date-res="2" date-ref="7" data-groups='["all", "letters", "blue", "square"]'>f</div> </div> 

try use .append(val1,val2),

$('#grid div.item[data-res][data-ref]').each(function(){   var $this = $(this);   $this.append($this.data('res'),$this.data('ref')); }) 

demo

your html contains wrong attribute names instead of data- use,

<div id="grid">     <div class="item blue" data-res="8" data-ref="13" data-groups='["all", "letters", "blue", "square"]'>d</div>     <div class="item green" data-res="9" data-ref="10" data-groups='["all", "letters", "blue", "square"]'>e</div>     <div class="item green" data-res="2" data-ref="7" data-groups='["all", "letters", "blue", "square"]'>f</div> </div> 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -