-2

I don't understand why attr() isn't working (see code below). I can see correct tag with the attribute in sources, tag is creating but it's not visible on the website.

app.html('<h1>' + product.name + '</h1><img src="' + product.img + '" width="300"></img><a></a>');
$('a').attr("href", product.link);

2 Answers2

1

No content is in the <a> tag. That's why.

<a>1st tag</a>
<a></a><!--Second tag-->
1

1st: by using not visible on the website. this is because the <a></a> doesn't have any content

2nd : about the </img> you can take a look at Why is the <img> tag not closed in HTML?

Mohamed-Yousef
  • 23,946
  • 3
  • 19
  • 28