zsharp zsharp -4 years ago 153
jQuery Question

How to get element value in jQuery

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

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download