Jquery – How to get element value in jQuery

jquery

Why is it not returning value in 'li'? What am i doing wrong?

$("#list li").click(function() {
    var selected = $(this).val();
    alert(selected);
})

Best Solution

Did you want the HTML or text that is inside the li tag?

If so, use either:

$(this).html()

or:

$(this).text()

The val() is for form fields only.