var titleLink=document.createElement("a");
titleLink.setAttribute("href",'answers[3][i]');
titleLink.innerHTML=answers[1][i];
newDiv.appendChild(titleLink);
When I click on the link when created through js, it shows page not found. But the same link when I add it explicitly using <a> tag in html opens correctly. What could be the problem??
Link to the entire code is here: http://codepen.io/jpninanjohn/pen/GZrzoG
titleLink.setAttribute("href",answers[3][i]);, remove the quotes ofanswers..href, try removing the quotesanswers[3][i]. Also try using the console to debug:console.log(titleLink.href).