The use of events in jQuery

The use of events in jQuery

Hello,

i try to use jQuery for the first time. Most things are self-explanatory but I am stuck on the use of events. Example:

  1. function foo(){
  2. var html = '<div id="mydiv">';
  3. html += '<input type="text"  id="myid" name="myname" />' ;
  4. html += '</div>';
  5. //adding html to document
  6. $('#bar').empty().append(html);
  7. //now adding events
  8. $('#bar div').dblclick(function(e){dosomething(e)});
  9. }
  10. function dosomething(e){
  11.   //How do I get the id of the div here?
  12.   //this.id doesn't work and e.target.id returns
  13.   //the id of the input field
  14. }

Ok now to the questions.

1. Did I assign the event right? I create some html-elements dynamical and want to assign events to them. But I am a little unsure if this the right way to do it (it works but I want to make sure anyway).
2. Now to the part where I am stuck. I want to do some changes on the <div> ondblclick (like some changes of the background). Normally I would work with this.id to get the id of the <div> and then work  with getElementById() .  How is this done in jQuery?


Thanks for your Help

Markus

PS: Sorry for my bad English.