How do you access the ui.item children in jQuery?
I'm trying to access the following rectangularized item using the jQuery sortable plugi开发者_Go百科n:
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!
Try this way:
alert(ui.item.context.childNodes[0].id)
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
精彩评论