I have a checkboxlist where each item has an id. When the text of an item is clicked the id("cssId") should be printed out in console.log.
Checkboxlist:
<div id="cssListBox" class="list-group">
<ul id="listItemCss">
@foreach (var item in Model.CssTemplates)
{
<li id="itemInList">
@Html.CheckBox("ChoiceBox", item.IsConnected)
@Html.Hidden("cssId", item.Id, new { @class = "cssId" })
</li>
}
</ul>
</div>
Jquery:
$('#listItemCss>li').click(function() {
var cid = (this).val();
console.log('cid');
});
Please tell me if I can make the question more clear in some way, I am a bit slow so have patience.
$('#listItemCss>li').click(function() {
var cid = $(this).find('.cssId').val();
console.log(cid);
});
Also, don't use the same id
for multiple li
elements
See Why is it a bad thing to have multiple HTML elements with the same id attribute?
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments