I have a function where when an element is clicked, it makes that element the selected element in a an Object. Let me show you.
var elem = new Object();
elem = {
title:'',//string
num:null,//number
selected:null
}
function selected(elem){
elem.title = elem.getAttribute("title") || this['title'];
alert(elem.title);
for(x=0;x<classIds.length;x++){
if(elem.title==classIds[x].name){
elem.num=x;
elem.selected=classIds[x];
alert(elem.selected.properties);
}
}
}
So when an element is clicked, the selected function runs from an onlick attr on the element. Which is cool. It works fine. But, if you click on it again, the browser gives the error Object is not a function. This only happens when you click on the same element consecutively. If you click on another element, it doesn't happen. Which is weird because the function should be running a seperate time and overwriting the Object elem (which is defined outside the function as a global variable/object). I have the alert for reasons of debugging. Also, the array classIds is defined out of the function as well. Any insight would be great. Also, I know my coding is a little odd, I am really just starting with Objects and Methods in JavaScript.
Edit
Onclick is called like this below
<li title="+classIds[x].name+" onclick='selected(this)'>"+classIds[x].name+"</li>
So...
onclick='selected(this)'
Is the the call
selected(). The issue is likely with the argument passed to that function.