1

I want to trigger a function when I control+click on a html>table>tr and also trigger another function when I don't use a control key.

Explanation:

Here I have a html table. I have binded on click function to the table>tr and a fancybox is show on click of this tr.

But now I want to click the same tr within a specific td but the first function is getting invoked even if I specify the id of specified table>tr>td.

I have applied the table>tr a class and href for the fancybox to appear and when I close the fancybox the class and href gets removed according to my wish.

But now When I wanted to use the same tr and click on the td of that tr and invoke another fancybox, the class and href is being applied to the td but the fancybox doesn't appear belonging to the td but appears belonging to the tr.

       $('#tbl').on('click','tbody tr',function(){
                  //fancybox 1 to be appeared
       }); 



       $('#tbl').on('click','tbody tr td#comm',function(){
                  //fancy box 2 to be appeared..
       });

If required ctrl or alt or shift keys can be applied

kishore
  • 33
  • 7
  • Have a look at the following http://stackoverflow.com/questions/2485345/javascript-or-jquery-event-handlers-for-ctrl-shift-mouse-left-button-click – Simranjeet Singh Oct 20 '14 at 07:20
  • Be aware that ID's in HTML doms are unique. You cannot have multiple TD's with the ID "comm". Thus, if you only want to have one TD with this ID, you can shorten your selector down to: $('#comm).click(function(){ //your function }); – Ole Haugset Oct 20 '14 at 07:21

2 Answers2

0

e.ctrlKey is true when Ctrl is pressed (where e is the event object from the first parameter of the event handler):

$('tbl').on('click', 'tbody tr', function(e) {
   if (e.ctrlKey) {
      //fancybox 1 to be appeared
   }
}); 

Also, you have shitKey and altKey that are true when they are pressed.

Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
  • @Ionica Bizau . thanks for the comment. but I want a ctrl click for the second fancybox and for the first one only a normal click – kishore Oct 20 '14 at 07:26
  • @kishore You can add an `else` and handle there *normal* clicks. – Ionică Bizău Oct 20 '14 at 07:48
  • having a problem using this, because I even have to render response from the fancybox and display in the td.. when i click it by ctrl+click then I am getting the form load which I seen through debugging tool but sometimes it display the fancybox. please help – kishore Oct 20 '14 at 10:38
  • @kishore Ask another question for that. Sounds like another issue. – Ionică Bizău Oct 20 '14 at 11:14
  • http://stackoverflow.com/questions/26464866/issue-with-using-ctrl-and-click-jquery/26467018#26467018 – kishore Oct 22 '14 at 09:40
0

you can also use preventDefault() docs are here.Hope that helps.

Aameer
  • 1,366
  • 1
  • 11
  • 30