I am having total 10 images with ID's in a div. Now I want to show those images depending on arrow keypress in a specific sequence 1a, cv2, w3i, e4, re5, we6i, w7i, w8i, in, xxi irrespective of their position in div. Now, when the arrow press second time then it should show second image in that series. Also, if the image in the div are less than 10 suppose 4. Then also, they should show in the same sequence as they show, when there were 10 imges. Please look at my example,
$("img").hide();
//pressing arrow button first time
$(document).keydown(function(e) {
if (e.which == 39) {
//show 1a
//if 1a does not exist, then show cv2
//if 1a,cv2 does not exist, then show w3i
//if 1a,cv2,w3i does not exist, then show e4
//and so on.
}
});
//pressing arrow button second time
$(document).keydown(function(e) {
if (e.which == 39) {
//show the second img in series after as first already shown in first press
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Example1: If div has 10 images -->
<div class="img">
<img id="xxi" src="#">
<img id="re5" src="#">
<img id="w8i" src="#">
<img id="w3i" src="#">
<img id="we6i" src="#">
<img id="1a" src="#">
<img id="w7i" src="#">
<img id="in" src="#">
<img id="cv2i" src="#">
<img id="e4" src="#">
</div>
<!-- Example2: If div has 4 images -->
<div class="img">
<img id="w3" src="#">
<img id="w7" src="#">
<img id="1a" src="#">
<img id="e4" src="#">
</div>