$(document).ready(function(){ $("button").click(function(){ var i = $('.selected').index($('li')); $(this).text(i) }) })