Why when I use .prev() (the same goes with .next()) here to launch all audios except the one before r2, it starts all except r2 and some random one (not exact previous)? It should play only the previous to the r2 element. I try to understand this
<html>
<head>
<script type="text/javascript" src="RadioN.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("#i1").click(function(){
var player = $("audio").not("#r2").prev();for(i=0; i<player.length; i++) player[i].play();
});
});
</script>
</head>
<body>
<a href="#">
<img id="i1" src="r1.png" style="height:50px"></a><br>
<div>
<audio class="r" id="r1" src="https://rs103-krk-cyfronet.rmfstream.pl/RMF24" controls preload="none" style="visibility: visible"></audio>
<audio class="r" id="r2" src="https://radiostream.pl/tuba10-1.mp3" controls preload="none" style="visibility: visible"></audio>
<audio class="r" id="r4" src="https://c13.radioboss.fm:18296/stream" controls preload="none" style="visibility: visible"></audio>
<audio class="r" id="r5" src="http://stream.affordablestreaming.com:8000/KDDL.mp3" controls preload="none" style="visibility: visible"></audio>
<audio class="r" id="r6" src="https://p10.p4groupaudio.com/P10_MM" controls preload="none" style="visibility: visible"></audio>
</div>
</body>
</html>
jQuery's prev method will return the array of previous siblings of the elements matching .not('#r2').
.not('#r2') will return [audio#r1.r, audio#r4.r, audio#r5.r, audio#r6.r].
.not('#r2').prev() will return [audio#r2.r, audio#r4.r, audio#r5.r].
This is :
#r1 previous sibling will return none#r4 previous sibling will be #r2#r5 previous sibling will be #r4#r6 previous sibling will be #r5If what you want is to play only the previous sibling to #r2 you should use a more deterministic selector. something like $("audio#r2").prev().get(0).play() may be?