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:
- function foo(){
- var html = '<div id="mydiv">';
- html += '<input type="text" id="myid" name="myname" />' ;
- html += '</div>';
- //adding html to document
- $('#bar').empty().append(html);
- //now adding events
- $('#bar div').dblclick(function(e){dosomething(e)});
- }
- function dosomething(e){
- //How do I get the id of the div here?
- //this.id doesn't work and e.target.id returns
- //the id of the input field
- }
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.