How do I get the id of a list item?

FadiY

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.

AmmarCSE
$('#listItemCss>li').click(function() {
    var cid = $(this).find('.cssId').val();
    console.log(cid);
});

Also, don't use the same id for multiple li elements

DEMO

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do i get id of autocomplete textview out of two autocomplete textview on item selected from its list?

From Dev

How do I get the ID of a JQuery item mid-function?

From Dev

How Do I Get ID From Item In DropDownList?

From Dev

How do I get a list item by index in elm?

From Dev

how do i get the value of a list item on list item tap in jquery mobile

From Dev

How do you get the Id of the item in CheckListBox

From Dev

How do I navigate between List and Item?

From Dev

How do I get an item from an icollection via index when in the class contrusctor I set the icollection as a list?

From Dev

How do I get an item from an icollection via index when in the class contrusctor I set the icollection as a list?

From Dev

How do i get item by ID from a loop of Rows.count

From Dev

How do i get item by ID from a loop of Rows.count

From Dev

How do I get the selected item from drop down list and submit it to my Details view?

From Dev

How do I generate a list for each list item

From Dev

How do I generate a list for each list item

From Dev

How do I get id of comment

From Dev

How do I use the Ruby twitter gem to get a list of followers for a given ID/handle?

From Dev

How do I get a list of settings in which settings should grouped by an ID in Hibernate.find()

From Dev

How do I get an id from a student in a list and display it the student's information on another page? Ruby on Rails

From Dev

How to get listitem id when I click on PopUp menu item?

From Dev

How can i get Id item number in entity data model

From Dev

How do I print an item and the list it came from in Python?

From Dev

How do I tell python to NOT print an item in a list?

From Dev

how do I set a list item by index in jinja2

From Dev

How do I use Bootstrap columns inside a list item?

From Dev

How do I replace an item in List(Of String) in VB.NET?

From Dev

How do I align values inside my listview list item?

From Dev

How do i remove an item from a list and store it into a variable in python

From Dev

How do I add text to every other item in a python list?

From Dev

How do I replace an item in List(Of String) in VB.NET?

Related Related

  1. 1

    How do i get id of autocomplete textview out of two autocomplete textview on item selected from its list?

  2. 2

    How do I get the ID of a JQuery item mid-function?

  3. 3

    How Do I Get ID From Item In DropDownList?

  4. 4

    How do I get a list item by index in elm?

  5. 5

    how do i get the value of a list item on list item tap in jquery mobile

  6. 6

    How do you get the Id of the item in CheckListBox

  7. 7

    How do I navigate between List and Item?

  8. 8

    How do I get an item from an icollection via index when in the class contrusctor I set the icollection as a list?

  9. 9

    How do I get an item from an icollection via index when in the class contrusctor I set the icollection as a list?

  10. 10

    How do i get item by ID from a loop of Rows.count

  11. 11

    How do i get item by ID from a loop of Rows.count

  12. 12

    How do I get the selected item from drop down list and submit it to my Details view?

  13. 13

    How do I generate a list for each list item

  14. 14

    How do I generate a list for each list item

  15. 15

    How do I get id of comment

  16. 16

    How do I use the Ruby twitter gem to get a list of followers for a given ID/handle?

  17. 17

    How do I get a list of settings in which settings should grouped by an ID in Hibernate.find()

  18. 18

    How do I get an id from a student in a list and display it the student's information on another page? Ruby on Rails

  19. 19

    How to get listitem id when I click on PopUp menu item?

  20. 20

    How can i get Id item number in entity data model

  21. 21

    How do I print an item and the list it came from in Python?

  22. 22

    How do I tell python to NOT print an item in a list?

  23. 23

    how do I set a list item by index in jinja2

  24. 24

    How do I use Bootstrap columns inside a list item?

  25. 25

    How do I replace an item in List(Of String) in VB.NET?

  26. 26

    How do I align values inside my listview list item?

  27. 27

    How do i remove an item from a list and store it into a variable in python

  28. 28

    How do I add text to every other item in a python list?

  29. 29

    How do I replace an item in List(Of String) in VB.NET?

HotTag

Archive