Ankita Kashyap Ankita Kashyap - 1 year ago 67
HTML Question

Javascript dynamic creatationg of anchor tag is not working

i am trying to create html with JavaScript. but my link to anchor tag is not working as expected.

var test ="'t_principals_being_coached.html?cmp=SOC-EDIT-FB";

var res ="<a style='color:#7Bc76B;text-decoration: none;' target='_blank' href='"+test+"'>Link to read more ></a>";

document.getElementById("res").innerHTML = res;

Any help will be appreciated.


Answer Source

You can simply modify your <a> declaration as follows to take care of single quote present in your URL:

var res ='<a style="color:#7Bc76B;text-decoration: none;" target="_blank" href="'+test+'">Link to read more ></a>';

declared within single quote as above and all attributes are within double quotes

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download