jQuery – Data() atrribute returning undefined

I have a script that appends a piece of HTML 10 times

<div id="box${i}" class="divMusica">

    <div class="todas">

    <img  id= "img${i}" src="">


    <div class="divTexto">

        <h2>Nome da banda: <p id="banda${i}"></p></h2>

        <h2>Nome da música: <p id="musica${i}"></p></h2>

        <a class="referencia" id ="url${i}" href="" target="_blank" class="button">Ir para last.fm </a>

        <button button type="button" class="add-music-button" data-ref="${i}" onclick="add_to_storage()">Adicionar</button>



And I’m trying to get data-ref to the sessionStorage with this code let musicRef = $(this).data("ref"); but it returns undefined. Can someone tell me why? I already tried to put ${i} without quotes too.

16 thoughts on “jQuery – Data() atrribute returning undefined”

  1. 478781 878337Most appropriate the human race messages work to show your and present exclusive chance with particular couple. Beginer appear system in advance of raucous men and women will most likely always be aware most of the golden value off presentation, which is a persons truck. greatest man jokes 547389


Leave a Comment