Your code is working here, you may need to put it in document.ready()
or need to add jQuery files. Using this.id
instead of $(this).attr("id")
is better option here as it is javascript and gives you performance benefit.
$(document).ready(function(){
$("li").click(function() {
//var myid = $(this).attr("id");
alert(this.id);
});
})