My goal is to extract the value from the li attribute, id="@item1.TaskId"
, which is present in the li element when the page loads using jQuery. However, when the page loads and the jQuery script is executed, the value stored in the variable taskId (
var taskId = $("ul").find("li").attr("id");
) turns out to be undefined.Here is my HTML code that includes li elements with the id attribute,
id="@item1.TaskId"
:<div class="col-md-6" style="font-family:'Century Gothic'">
<div class="panel panel-default " id="@ViewBag.statusIdForTask" sId="@ViewBag.statusName">
<div class="panel-heading" style="text-align:center; font-size:16px;font-family:'Century Gothic'">@ViewBag.statusName</div>
<div class="panel-body">
<ul class="ui-sortable tasklistdiv sorttaskDP receive">
@foreach (var item1 in Model)
{
<li class="ui-sortable-handle panel-style bs-callout bs-callout-default receivepanel" id="@item1.TaskId" taskid="@item1.TskAssId" style="font-size:14px;text-align:justify; @styleClass">
}
</ul>
</div>
</div>
</div>
Below is My jQuery script:
<script>
$(document).ready(function () {
var taskId = $("ul").find("li").attr("id");
});
</script>