I've created a function(new Soldier) in a .js that creates an object with Class="unit" that when clicked, it will provide some information. When I put the function outside of all other functions(but still inside $(document).ready(function() {})
, it works perfectly. But when I put it inside another function(that contains an if statement), it creates the object(or at least the image), but the object doesn't do anything when clicked.
The one that works is simply:
Unit[selectedindex] = new Soldier(selectedindex);
But when set like this:
$('#startingSoldier').click(function() {
Unit[selectedindex] = new Soldier(selectedindex);
}
});
The object it creates doesn't work when clicked. I have a $('.unit').click(function(){}
.
Let me know if you need additional information on the click function or the Soldier method. Thank you for your help.