.active { background-color: aqua; }
<div id="list"> <span>1</span> <span>2</span> <span>3</span> <span>4</span> <span>5</span> </div>
var a = $("#list span"); console.log(a[0]); for (var i = 0; i < a.length; i++) { a[i].index = i; a[i].onclick = function () { for (var i = 0; i < a.length; i++) { a[i].className = '' } this.className = 'active' } }
Done !