getElementsByClassName
doesn't return an array, but an HTMLCollection
. Thus, it doesn't have array methods like indexOf
. You need to explicitly call array methods with a this
value of the HTMLCollection
like this:
var selected_id = Array.prototype.indexOf.call(arr, selected[0]);