I have the following html:
<div id="gallery">
<ul>
<li>
<a href="url I want to get">link</a>
</li>
</ul>
</div>
and some jQuery that allows it to be dropped on another div:
$trash.droppable({
accept: '#gallery > li',
activeClass: 'ui-state-highlight',
drop: function(ev, ui) {
deleteImage(ui.draggable);
var $flickrparenturl = $("a").attr("href"); //only gets href of <li> #1, not <li> being dragged
$.post("updateDB.php", { 'flickrparenturl': $flickrparenturl } );
}
});
What is the correct way to get the href attribute of the child of the element being dragged? $("a").attr("href"); is only getting the href of the 1st li on the page, not the one being dragged.
You can use:
This will look for the
a
element among all descendants of the draggable element.To look only at the direct children of the draggable, use this instead:
Try this:
$(this).children('a').attr("href");
Does that work for you?