Define image src tag using portion of an URL using JavaScript -
with code below, able variable without slash url html.
var patharray = location.pathname.split( '-' ); var urlwithoutdashes = patharray[0]; var urlwithoutslash = urlwithoutdashes.substring(1); document.write(urlwithoutslash); now i'd use img src tag (with extention .png), can't figure out how it. code below doesn't seem work.
var patharray = location.pathname.split( '-' ); var urlwithoutdashes = patharray[0]; var urlwithoutslash = urlwithoutdashes.substring(1); document.write("img src=\""urlwithoutslash".png\">"); how can solve this?
this line:
document.write("img src=\""urlwithoutslash".png\">"); should be:
document.write("<img src=\"" + urlwithoutslash + ".png\">");
Comments
Post a Comment