How do you access ui.item children in jQuery?

I am trying to access the following rectangular element using a sortable jQuery plugin: enter image description here

My jQuery code currently looks like this (note the question about even in the get section):

$( "#listA, #listB" ).sortable({ connectWith: ".connected_sortable", delay: 100, receive: function(event, ui) { alert(ui.item.text()); } }).disableSelection(); 

HTML:

 <ul id="listA" class="connected_sortable ui-sortable"> <li> <div id="4"> Test Text </div> </li> </ul> 

How do I access this identifier with a warning? I tried alert(ui.item.context.childNodes.id) and the warning returns "undefined".

changes: added HTML and clarified abit question.

Thanks!

+4
source share
4 answers

Try as follows:

 alert(ui.item.context.childNodes[0].id) 
+1
source

You can access the id of an element using .attr

 var id = $("yourSelector").attr("id"); 
0
source

try alert('ui.item >li').attr('id')

0
source

Here's the solution: http://jsfiddle.net/a8bNn/1/

  • Using "upgrade" instead of "receive"
  • use "ui.item.context.childNodes [1] .id" to capture id
0
source

All Articles