How can I alert the id of the item clicked?
- First
- Second
you can get the value of the respective li by using this method after click
HTML:-
show the value of li
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
JS:-
$("li").click(function ()
{
var a = $(this).attr("value");
$("#user").html(a);//here the clicked value is showing in the div name user
console.log(a);//here the clicked value is showing in the console
});
CSS:-
ul{
display: flex;
list-style-type:none;
padding: 20px;
}
li{
padding: 20px;
}