Ok this must have a simple solution but I'm breaking my head over this one...
I have a js code which picks up ID numbers from my HTML by class. It stores all in an array. I checked that the array is not undefined and is not empty. Sofar so good.
Now I need to get this array of ID's to display into an HTML element. The full array should just come out as a comma separated string.
The piece of code which is relevant:
function makelink(){
var idArray = $(".result");
document.getElementById("link").innerHTML = idArray;
}
//The result in HTML = [object Object]
When I do the following it works exactly as I want (except that I can't hardcode the array into the code like this of course)
function makelink(){
var idArray = ["123", "124", "125", "126"];
document.getElementById("link").innerHTML = idArray;
}
//The result in HTML = [123,124,125,126]
I read at least 4 other similar questions on Stackoverflow such as What does [object Object] mean? and Convert javascript array to string and based on that I tried:
document.getElementById("link").innerHTML = idArray.join();
and also:
var idArray = $(".result");
idArray.toString();
but I could not figure out how to make it work for my code. I don't need to alert or console.log. I need my result to be output in the HTML. Please help.