5

I am just curious; does any of you have any good javascriptresources for setting defaultbutton for all elements inside a div? I have a lot of divs that executes various javascriptfunctions and I would like all of them to have their buttons script executed when enter is pressed.

Thanks in advance!

femseks
  • 2,914
  • 3
  • 23
  • 20

2 Answers2

7

The way I would do it is give the elements that you want to be fired a class, for example 'acceptEnter'. Then create a handler for the containing DIVs which looks for that class on keypress. Hope this helps :)

$('div').keypress( function(e) {
   if(e.keyCode == '13') {
     $(this).find('.acceptEnter').click();
   }
});
John Strickler
  • 25,151
  • 4
  • 52
  • 68
0

Why not have a single javascript function that calls all the other scripts, and make all the buttons call this one javascript function?

Nivas
  • 18,126
  • 4
  • 62
  • 76
  • Not sure how that would help.. I then would need to know which method to call in the "master" javascript that handles everything.. – femseks Sep 24 '10 at 12:07