I need to get value form every list click
Here is my list:
<c:forEach items="${cmlist}" var="records">
<ol class="dd-list" id="chapterlist" >
<li id="cs" class="dd-item" data-id="1" value="${records.levelID}">
<div class="dd-handle">
<a href="#subchaptercontent">Chapter: ${records.levelName}</a>
</div>
</li>
</ol>
</c:foreach>
here is my click function code:
$(window).load(function(){
$("#chapterlist li a").on("click", function(){
level = $(this).parent('li').val();
console.log("level"+level);
});
});
Could you please help?
parent()
function only goes up one level of DOM, so it gets to your <div>
element and stops there. Use parents()
instead.
Note, that val()
will only work if value is an integer. Shouldn't be a problem with an ordered list, though, where value is the number of an item.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments