I want to make a script that goes through several elements. I’ve come up with the idea to give the HTML elements a numeric id value. id=0 and I use the following jquery for to access it.
var image_id = 0;//initializing the image id variable
var get_image = document.getElementById(image_id);//getting the element based on the ID
var image = $(get_image);//creating a selector
function doSomething()
{
image_id++;
}
//finally I use this line of code to display the number on screen to check it's value
$("span").text(image_id);
doSomething()
the code above does work properly as I want it to except for the image_id++ line…in a way. When I place an alert underneath it it does show me the value is increased however it;s not applied. the value displayed on the spanelement is always 0 the affected element is also not effected by the code. Could anyone point me out what I’m doing wrong or if it’s at all possible or suggest a more effective method I appreciate all feedback
try this: