[jQuery] Re: Detecting ctrl+click on an element
On 4 Feb, 14:38, Giovanni Battista Lenoci [EMAIL PROTECTED] wrote: The subject says it all... How I can detect a crtl+click on an element? try this, supposing #target is yout target var clickFn = function(){ alert(ctrl + click); $(this).unbind('click', clickFn); } $(document) .keydown(function(event){ if (event.keyCode == 17){ $(#target).click(clickFn); } }) .keyup(function(event){ if (event.keyCode == 17){ $(#target).unbind('click', clickFn); } });
[jQuery] Re: Detecting ctrl+click on an element
andrea varnier ha scritto: try this, supposing #target is yout target var clickFn = function(){ alert(ctrl + click); $(this).unbind('click', clickFn); } $(document) .keydown(function(event){ if (event.keyCode == 17){ $(#target).click(clickFn); } }) .keyup(function(event){ if (event.keyCode == 17){ $(#target).unbind('click', clickFn); } }); Thank you very much! -- gianiaz.net - Giovanni Battista Lenoci P.le Bertacchi 66 23100 Sondrio (SO) - Italy
[jQuery] Re: Detecting ctrl+click on an element
andrea varnier ha scritto: try this, supposing #target is yout target var clickFn = function(){ alert(ctrl + click); $(this).unbind('click', clickFn); } $(document) .keydown(function(event){ if (event.keyCode == 17){ $(#target).click(clickFn); } }) .keyup(function(event){ if (event.keyCode == 17){ $(#target).unbind('click', clickFn); } }); I was making some test, and I have little problem.. If I bind a function to an element with jquery style method: $('#target').bind('click', function() { dosomething(this); ) }); in my dosomething function I can retrieve the element clicked. With your syntax I can bind/unbind function but I can't call dosomething with this parameter. Sorry, I'm using jquery for awhile, but in javascript I'm very newbie... Thank you.. -- gianiaz.net - Giovanni Battista Lenoci P.le Bertacchi 66 23100 Sondrio (SO) - Italy
[jQuery] Re: Detecting ctrl+click on an element
On 4 Feb, 17:20, Jeffrey Kretz [EMAIL PROTECTED] wrote: Another way would be to use the ctrlKey property of the Click event: $('#element').click(function(e) { if (e.ctrlKey) { do_something(); } }); jQuery also normalizes this into the metaKey attribute which detects the CMD key on a Mac: $('#element').click(function(e) { if (e.metaKey) { do_something(); } }); LOL!! much simpler. thanks, I didn't know that :)
[jQuery] Re: Detecting ctrl+click on an element
Another way would be to use the ctrlKey property of the Click event: $('#element').click(function(e) { if (e.ctrlKey) { do_something(); } }); jQuery also normalizes this into the metaKey attribute which detects the CMD key on a Mac: $('#element').click(function(e) { if (e.metaKey) { do_something(); } }); -Original Message- From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of andrea varnier Sent: Monday, February 04, 2008 6:35 AM To: jQuery (English) Subject: [jQuery] Re: Detecting ctrl+click on an element On 4 Feb, 14:38, Giovanni Battista Lenoci [EMAIL PROTECTED] wrote: The subject says it all... How I can detect a crtl+click on an element? try this, supposing #target is yout target var clickFn = function(){ alert(ctrl + click); $(this).unbind('click', clickFn); } $(document) .keydown(function(event){ if (event.keyCode == 17){ $(#target).click(clickFn); } }) .keyup(function(event){ if (event.keyCode == 17){ $(#target).unbind('click', clickFn); } });
[jQuery] Re: Detecting ctrl+click on an element
On 4 Feb, 16:15, Giovanni Battista Lenoci [EMAIL PROTECTED] wrote: I was making some test, and I have little problem.. If I bind a function to an element with jquery style method: $('#target').bind('click', function() { dosomething(this); ) }); in my dosomething function I can retrieve the element clicked. With your syntax I can bind/unbind function but I can't call dosomething with this parameter. look at my code: var clickFn = function(){ alert(ctrl + click); $(this).unbind('click', clickFn); } you can still get what you need by using $(this) in the function for example: var $this = $(this); dosomething($this); naming the function is useful if your #target element has other functions bound to a click event. in that case doing a simple $(#target).unbind('click'); would unbind even functions you may want to keep. Thank you.. figurati, you're welcome :)
[jQuery] Re: Detecting ctrl+click on an element
Jeffrey Kretz ha scritto: Another way would be to use the ctrlKey property of the Click event: $('#element').click(function(e) { if (e.ctrlKey) { do_something(); } }); jQuery also normalizes this into the metaKey attribute which detects the CMD key on a Mac: $('#element').click(function(e) { if (e.metaKey) { do_something(); } }); Very cool, thank you all. -- gianiaz.net - Giovanni Battista Lenoci P.le Bertacchi 66 23100 Sondrio (SO) - Italy