views:

23

answers:

2

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!

A: 

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

Nivas
Not sure how that would help.. I then would need to know which method to call in the "master" javascript that handles everything..
femseks
+1  A: 

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
This was exactly what I was looking for :) Thanks!
femseks