javascript - id field not appending to div mvc 4 -


i have dialog opens items window. want select item click add have item's id appended div can submit db. i'm getting id in alert nothing appending. want append on add button click trying on click of li isn't working either.

dialog options

   $('.ita').dialog({  autoopen: false,  draggable: true,  width: 450,  resizable: false,  dialogclass: "ui-dialog",  modal: true,  show: { effect: 'fade', duration: 200 },  buttons: [{  id: "addtoaddpage",  text: "send trade",  click: function () {     // on close item selected added `div ita`   //$(this).dialog("close");    }); 

get <li> clicked , append div ita

  $(".ita").on("click", "li", function () {    //get div       var div = $("#divtoaddto");        //get id of item     var itemtoadd = $(this).attr("data-id");          alert(itemtoadd);//for debug      //apendto?     $(itemtoadd).appendto(div);     }); 

the view selected items should go

@model ienumerable<item>  @{ viewbag.title = "tradepage"; } <div id="item">   @foreach (var item in model)  {  <ul>     <li>         @html.displayfor(modelitem => item.id)     </li>      <li>         @html.displayfor(modelitem => item.item_name)     </li>     <li>         @html.displayfor(modelitem => item.item_description)     </li> </ul>   }  </div>  <div id="addnav">   <a class="allitemsbtn" href='@url.action("getitemstoadd")' >add file...</a>   <a class="submitadds" href="#" >submit</a>     </div>   <div class = "ita"></div>   <div id = "addeditems">added items go here</div> 

view items are

@foreach (var item in model)  {  <ul>     <li data-id = "@item.id">         @html.displayfor(modelitem => item.id)     </li>      <li>         @html.displayfor(modelitem => item.item_name)     </li>     <li>         @html.displayfor(modelitem => item.item_description)     </li>   </ul>  }   <div id="additembtn"> <button id="addtoapage">add</button>   <p><a id="addtoadd" href="#">add</a></p>  </div> 

replace

$(itemtoadd).appendto(div);  

with:

div.text(itemtoadd);  

that should update contents of div selected id. here simple example: jsfiddle . click on 1 of list items see id updated.


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 -