deepu07's avatar
Level 11

Dynamic href tag with id

Hello mates, this is my code snippet Here I'm trying to make a dynamic anchor tag by passing id. somehow I'm getting a static value in return. any help that would be great. TIA.

for (var i=0; i<data.length; i++) {
                if (data[i].trip === 'oneway'  {
                    trHTMLLeft += '<tr><td>' + data[i].departure_at + '</td><td>' + '<button type="button" class="btn btn-success"><a href="show-ride/"+data[i].id>More</a></button>' + '</td></tr>'
            }
0 likes
3 replies
Tray2's avatar

You should never mix <button>and <a> in the same tag.

1 like
Scooby's avatar
Scooby
Best Answer
Level 7

What @Tray2 said and then clean up the code a bit and maybe it'll work?

for (var i=0; i < data.length; i++) {
    if (data[i].trip === 'oneway') {
        trHTMLLeft += '<tr><td>' + data[i].departure_at + '</td><td><a href="show-ride/' + data[i].id + '" class="btn btn-success">More</a></td></tr>';
    }
}

Please or to participate in this conversation.