Juan Prado Juan Prado - 26 days ago 6
HTML Question

How can change the name or attribute of a link in Javascript

How can change the name or attribute of a link in Javascript

I have following code:

var id="0014"
cell1.innerHTML = '<a href={{url_for('static',filename='+id+'".txt")}}">'+id+'</a>';


The name of link is ok but the address not

I only get 0014

The link is:

htp://my_address/static/+id+.txt


instead of:

htp://my_address/static/0014.txt


Thanks for your help

Answer

Try this:

cell1.innerHTML = '<a href={{url_for('static', filename='')}}' + id + '.txt>' + id + '</a>';

url_for() will generate a link like this: .../static/<filename>. If you use url_for('static', filename=''), it generate a link like: .../static/, so you can just add text after it (i.e. + id + '.txt>') .