I have a task that requires the following:
Implement an event listener so that when you click on any list item, the value of its "value" attribute will be shown next to this line.
In my HTML, I have an ordered list with 8 list items. The values range from 1 to 8. This is the current code I have:
$("li").click(function () {
var value = $(this).attr("value");
$("#spanFieldId").text(value);
});`
The issue I am facing is that it always displays 1 no matter which list item I click on. How can I modify the jQuery code to select the specific list item that was clicked, retrieve its value attribute, and display it on the webpage? The HTML for the list items is as follows:
<li value="3">blablablabla</li>
<li value="4">blablablabla</li>
<li value="5">blablablabla</li>
Any suggestions on how to fix this issue?