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