Search code examples
javascripthref

javascript concatinate href


I am having trouble creating an href based on an array. Here is what I have:

document.write('<a href="monthName[thisMonth].htm">'+monthName[thisMonth]+'</a>');

I need the monthName[thisMonth].htm to be based off an array monthName, with the position of thisMonth. The title element is working fine, but somehting is wrong with the link element.


Solution

  • If you don't need any additional escaping, you can just do:

    document.write('<a href="' + monthName[thisMonth] + '.htm">'+monthName[thisMonth]+'</a>');