javascript - get all data from one list item jquery mvc 4 -


i want click on 1 row , id posting db , name dsiplay user.

with code have click on corresponding <li> (data-id or data-name) value. how both <li>? hidden-fields, maybe?

  $(".ita").on("click", "li", function () {     var div = $("#addeditems");     var itemtoadd = $(this).attr("data-id");     var name = $(this).attr("data-name");     alert(itemtoadd + name);     var itemtoadd = ("<li class = " + itemtoadd + ">"+ name +"</li>");     alert(itemtoadd);     $(itemtoadd).appendto(div);    // div.html(itemtoadd);   }); 

view

@foreach (var item in model) {  <ul>     <li data-id = "@item.id">         @html.displayfor(modelitem => item.id)     </li>      <li data-name="@item.item_name">         @html.displayfor(modelitem => item.item_name)     </li>     <li>         @html.displayfor(modelitem => item.item_description)     </li> </ul> } 

try:

$(".ita").on("click", "li", function () {     var div = $("#addeditems");     //get nearest parent     var parent = $(this).closest("ul");     //from parent, access both li     var itemtoadd = parent.find("[data-id]").attr("data-id");     var name = parent.find("[data-name]").attr("data-name");     alert(itemtoadd + name);     var itemtoadd = ("<li class = " + itemtoadd + ">"+ name +"</li>");     alert(itemtoadd);     $(itemtoadd).appendto(div);    // div.html(itemtoadd);   }); 

demo


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -