TransWikia.com

Element goes out of the element in JS

Stack Overflow Asked on December 9, 2021

I have a very strange problem that I never seen before. Please check my code below and guide me where I am wrong.

Actually the problem is I put a name inside the anchor tag and when I load the page it appears out of the anchor tag.

Code

   html += "<h6>";
   html += "<a href=" + val.destination_url + ">" + val.product_name + "</a>";
   html += "</h6>";

Output

enter image description here

One Answer

Your href attribute is not inside of "...". You need to add those, that might fix your problem.

html += "<h6>";
html += "<a href="" + val.destination_url + "">" + val.product_name + "</a>";
html += "</h6>";

Or for readability’s sake, use backticks:

html += "<h6>";
html += `<a href="${val.destination_url}">${val.product_name}</a>`;
html += "</h6>";

Answered by MauriceNino on December 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP