Question

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!

Was it helpful?

Solution

Try this way:

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

OTHER TIPS

You can access id of an element with .attr

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

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

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

  • Using "update" instead of "receive"
  • use "ui.item.context.childNodes[1].id" to grab the id
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top