How do you access the ui.item children in jQuery?

EverTheLearner picture EverTheLearner · Oct 3, 2011 · Viewed 9.4k times · Source

I'm trying to access the following rectangularized item using the jQuery sortable plugin: enter image description here

Currently my jQuery code looks like this (Note the question is about the even in the receive 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 would I access that id using the alert? I tried alert(ui.item.context.childNodes.id) and the alert returns an 'undefined'.

edits: added HTML and clarified the question abit.

Thank you!

Answer

ctekse picture ctekse · Oct 3, 2011

Try this way:

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