There are a few different issues with your code.
- You used strings instead of the actual code structure references while calling
display. I see that you mean for these to reference the element ids, but you must first get the element with document.getElementById(...) or jQuery's $("#...").
- In the
pop and clickArea arrays, you used strings, which do not have the .style object. You need to reference the elements themselves.
- Your code structure is not designed to handle arrays.
- You need to define the
addEventListener before you need the function handler to be called. You do not want this every time.
- The
click argument in the display function is redundant, as it is never called.
- You are using jQuery. You should have stated this! (but you're forgiven) :)
- You can't reach into arrays with the syntax
arrayName[#,#,#].
- You misspelled "display". Whoops!
- The arrays are redundant, since the code needed to be restructured.
First, in order to address Point #4, we need this code to run when the DOM has finished loading:
var clickArea = new Array("click1","click2","click3","click4","click5","click6");
clickArea.each(function(id){
$("#"+id)[0].addEventListener("touchend", display);
});
Next, we need to fix the issues with your code. They're explained above.
var pop = new Array("pop1","pop2","pop3","pop4","pop5","pop6");
function display(event){
var indx = Number(event.target.id.split(/\D/i).join(""));
$("#pop"+indx)[0].style.display = "block";
pop.each(function(ide) {
if (ide.split(/\D/i).join("") != indx-1) {
$("#"+ide)[0].style.display = "none";
}
});
};
Otherwise, great job! All of us started out like this, and believe in you! Keep it up!
P.S. You can set arrays like this [ ? , ? , ? , ? ] instead of this new Array( ? , ? , ? , ? ).