1

I've got a relatively complicated jQuery UI sortable, which I'm able to drag in elements from somewhere else. I'm using the following code, and am attempting to find the first element inside of what's been dropped with a class of editable, and trigger a click on it. This isn't working. I've thrown in some alerts and a console.log of ui.item[0].innerHTML returns an object with the correct DOM elements in it. So, I'm not quite sure what's going on here.

stop : function(event, ui){
   $(ui.item[0].innerHTML).find('.editable').first().trigger('click');
}

Can anybody throw some of their wisdom my way? I'd greatly appreciate it. Just to note - if I click on the added element manually, it works as expected.

Thank you!

3
  • did you try to click on it yourself? What's happening? Commented Aug 12, 2011 at 20:40
  • Hey Alexis - yes, clicking on it works. Sorry about the confusion - I'll update the question. Thanks1 Commented Aug 12, 2011 at 20:41
  • I suppose that calling "click()" directly on it doesn't change anything? Commented Aug 12, 2011 at 20:47

2 Answers 2

3

I would guess that you want just $(ui.item[0]) and not $(ui.item[0].innerHTML) because innerHTML returns the HTML syntax of the element ui.item[0] (a string) and not references to the DOM nodes like you want.

Sign up to request clarification or add additional context in comments.

Comments

1

$(ui.item[0].innerHTML) creates a new element. So triggering an event on this element is useless.

Use $(ui.item[0]) instead.

2 Comments

It looks like you beat me by 37 seconds, what do we do now?
Haha wow - you both rock! Thank you so much. I upvoted both, but I guesss since TheifMaster was ahead by 37 seconds, I've got to give it to them. Thank you, @nwellcome, though!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.