Lets say I have an array of variables, I want to iterate through the array and change only a specific variable. Here's an example at the top of my head to illustrate what I mean.
function click() {
var p1 = document.getElementById("p1"); //a paragraph
var p2 = document.getElementById("p2"); //a paragraph
var img = document.getElementById("img"); //an image
var arr = [p1, p2, img];
for(i = 0; i < arr.length; i++) {
//Herein lies the problem
if (arr[0] == img) { ---Or--- if (i == newarr.indexOf(img)) {
arr[0].style.display = "none";
}
}
}
In the snippet above, both if conditions do not work. How do I check if an element is a specific variable?