I have been trying to create a hyperlink using a variable defined earlier in the same function to append:
var NAMEVARIABLE = responseArray[i].Name;
var TITLE_Game = document.createElement("p");
TITLE_Game.className = "TITLE_Game";
TITLE_Game.innerHTML = "<a href='Game_NAMEVARIABLE.html'>Games</a>";
I have tried the following using the solution found here: Passing Javascript variable to <a href >
<a href="Game_.html" onclick="location.href=this.href+'?key='+NAMEVARIABLE;return false;">Games</a>
But that didn’t work. I then tried adding an ID:
<a id="link" href="Game_.html?propid=">Games</a>
And adding this to the script: document.links["link"].href += NAMEVARIABLE;
This didn’t work either. These links are occuring within Isotope, which I’ve run into newbie-problems making sure my JSON data is loading before the script executes. That’s all working now, but I’m not sure if the reason the above methods aren’t working is because of a similar issue, or if they simply are not the proper way to go about this.
Any help is much appreciated. Thank you
first of all, try debug your variable :
is it returning the desired return value or not.
and then the second thing, in your first style of script, try this instead :
I assumed you have (static) html collection with
game_[number_id].htmlformatand if it’s so, you can try further with your second style of script, and change it to this :
you need to learn further about javascript strings concatenation